Skip to content

ane/vigil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vigil Build Status Clojars Project EPL

Vigil creates Manifold streams from files. You place a watcher on a file and the stream produces content as new content is appended to the file.

[vigil "0.1.1"] ; add this to your project.clj

Vigil can be used to monitor logs asynchronously as a stream. If you are creating an event-driven system, it's easy to create an event filter with Vigil.

Because the produced streams are Manifold streams, which act as a general-purpose compability layers for asynchronous communication, the file streams can be easily connected into other Clojure constructs, such as core.async, lazy sequences, promises, the list goes on.

For more information, see the documentation.

(require '[vigil.core :as v]
         '[manifold.stream :as s])

;; /foo/bar/baz contains "hello\nworld"
(def stream (v/watch-file "/foo/bar/baz"))

@(s/take! stream)
;; => ("hello" "world")

(spit "/foo/bar/baz" "blah\n" :append true)

;; the new line has now been pushed to the stream
@(s/take! stream)
;; => ("blah")

;; shut down the watcher
(s/close! stream)

Usage

The watcher can be stopped at any time by closing the stream. If you don't want to receive the initial content, pass false to the initial parameter in watch-file. If you delete or truncate the file, the watcher will stop and the stream will be closed.

For more information, see the documentation.

License

Copyright © 2016 Antoine Kalmbach ane@iki.fi

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.