Coder Social home page Coder Social logo

clojure-watch's Introduction

clojure-watch

The most user-friendly file-system watch library written in Clojure, built on top of the Java 7 WatchEvent API.

Installation

Add this to your dependencies:

[clojure-watch "LATEST"]

Check out Clojars for more specific installation instructions.

Usage

An example:

(ns clojure-watch.example
  (:require [clojure-watch.core :refer [start-watch]]))

(start-watch [{:path "/some/valid/path"
               :event-types [:create :modify :delete]
               :bootstrap (fn [path] (println "Starting to watch " path))
               :callback (fn [event filename] (println event filename))
               :options {:recursive true}}])

You call start-watch with a collection of specifications. A specification is a map with five entries:

  1. :path. The path to a directory that you want to watch.
  2. :event-types. A collection of the types of events that you want to watch. Possible values include :create, :modify, and :delete.
  3. :bootstrap (optional). A function to be run only once when start-watch is invoked. The function should accept one argument: the path given in the spec.
  4. :callback. A callback function to be invoked when an event occurs. The function should accept two arguments, the first one being the type of the event that happened (:create, :modify, or :delete), and the second one being the full path to the file to which the event happened.
  5. :options. A map of options. Currently the only available option is :recursive. If it's set to true, all sub-directories will be watched.

Stop the watch

start-watch returns a function that can be called to stop the watch. For example:

(let [stop-watch (start-watch [{ :path "/some/valid/path" :event-types [:create :modify :delete] :callback (fn [event filename] (println event filename))}])] ; start the watch (Thread/sleep 20000) ; manipulate files on the path (stop-watch)) ; stop the watch

License

WTFPL.

clojure-watch's People

Contributors

derekchiang avatar deathtenk avatar mdpendergrass avatar alxschwarz avatar rosejn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.