diff options
Diffstat (limited to 'stdlib/source/library/lux/world/file/watch.lux')
-rw-r--r-- | stdlib/source/library/lux/world/file/watch.lux | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/stdlib/source/library/lux/world/file/watch.lux b/stdlib/source/library/lux/world/file/watch.lux index 8b100638b..645c4e99e 100644 --- a/stdlib/source/library/lux/world/file/watch.lux +++ b/stdlib/source/library/lux/world/file/watch.lux @@ -29,7 +29,7 @@ [time ["[0]" instant {"+" Instant} ("[1]#[0]" equivalence)]] [type - [abstract {"+" abstract: :representation :abstraction}]]]] + [abstract {"+" abstract: representation abstraction}]]]] ["[0]" //]) (abstract: .public Concern @@ -40,7 +40,7 @@ (def: none Concern - (:abstraction + (abstraction [#creation false #modification false #deletion false])) @@ -48,14 +48,14 @@ (template [<concern> <predicate> <event> <create> <modify> <delete>] [(def: .public <concern> Concern - (:abstraction + (abstraction [#creation <create> #modification <modify> #deletion <delete>])) (def: .public <predicate> (Predicate Concern) - (|>> :representation (the <event>)))] + (|>> representation (the <event>)))] [creation creation? #creation true false false] @@ -67,7 +67,7 @@ (def: .public (also left right) (-> Concern Concern Concern) - (:abstraction + (abstraction [#creation (or (..creation? left) (..creation? right)) #modification (or (..modification? left) (..modification? right)) #deletion (or (..deletion? left) (..deletion? right))])) @@ -83,14 +83,14 @@ (type: .public (Watcher !) (Interface - (: (-> Concern //.Path (! (Try Any))) - start) - (: (-> //.Path (! (Try Concern))) - concern) - (: (-> //.Path (! (Try Concern))) - stop) - (: (-> [] (! (Try (List [Concern //.Path])))) - poll))) + (is (-> Concern //.Path (! (Try Any))) + start) + (is (-> //.Path (! (Try Concern))) + concern) + (is (-> //.Path (! (Try Concern))) + stop) + (is (-> [] (! (Try (List [Concern //.Path])))) + poll))) (template [<name>] [(exception: .public (<name> [path //.Path]) @@ -129,8 +129,8 @@ (do ! [last_modified (# fs last_modified file)] (in (dictionary.has file last_modified tracker)))) - (: File_Tracker - (dictionary.empty text.hash)) + (is File_Tracker + (dictionary.empty text.hash)) files))) (def: (available_files fs directory) @@ -186,8 +186,8 @@ (def: .public (polling fs) (-> (//.System Async) (Watcher Async)) - (let [tracker (: (Var Directory_Tracker) - (stm.var (dictionary.empty text.hash)))] + (let [tracker (is (Var Directory_Tracker) + (stm.var (dictionary.empty text.hash)))] (implementation (def: (start new_concern path) (do [! async.monad] @@ -308,8 +308,8 @@ (def: (default_event_concern event) (All (_ a) (-> (java/nio/file/WatchEvent a) Concern)) - (let [kind (:as (java/nio/file/WatchEvent$Kind java/nio/file/Path) - (java/nio/file/WatchEvent::kind event))] + (let [kind (as (java/nio/file/WatchEvent$Kind java/nio/file/Path) + (java/nio/file/WatchEvent::kind event))] (cond (same? (java/nio/file/StandardWatchEventKinds::ENTRY_CREATE) kind) ..creation @@ -374,8 +374,8 @@ (def: (default_poll watcher) (-> java/nio/file/WatchService (IO (Try (List [Concern //.Path])))) - (loop [output (: (List [Concern //.Path]) - (list))] + (loop [output (is (List [Concern //.Path]) + (list))] (do (try.with io.monad) [?key (java/nio/file/WatchService::poll watcher)] (case ?key @@ -386,10 +386,10 @@ (do ! [.let [path (|> key java/nio/file/WatchKey::watchable - (:as java/nio/file/Path) + (as java/nio/file/Path) java/nio/file/Path::toString ffi.of_string - (:as //.Path))] + (as //.Path))] the_concern (..default_key_concern key)] (again {.#Item [the_concern path] output})) @@ -402,13 +402,13 @@ (-> Concern (List Watch_Event)) ($_ list#composite (if (..creation? concern) - (list (:as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_CREATE))) + (list (as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_CREATE))) (list)) (if (..modification? concern) - (list (:as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_MODIFY))) + (list (as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_MODIFY))) (list)) (if (..deletion? concern) - (list (:as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_DELETE))) + (list (as Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_DELETE))) (list)) )) @@ -417,49 +417,49 @@ (do (try.with io.monad) [watcher (java/nio/file/FileSystem::newWatchService (java/nio/file/FileSystems::getDefault)) - .let [tracker (stm.var (: (Dictionary //.Path [Concern java/nio/file/WatchKey]) - (dictionary.empty text.hash))) - - stop (: (-> //.Path (Async (Try Concern))) - (function (_ path) - (do [! async.monad] - [@tracker (stm.commit! (stm.read tracker))] - (case (dictionary.value path @tracker) - {.#Some [the_concern key]} - (do ! - [_ (async.future - (java/nio/file/WatchKey::cancel key)) - _ (stm.commit! (stm.update (dictionary.lacks path) tracker))] - (in {try.#Success the_concern})) - - {.#None} - (in (exception.except ..not_being_watched [path]))))))]] - (in (: (Watcher Async) - (implementation - (def: (start the_concern path) - (do async.monad - [?concern (stop path)] - (do (try.with async.monad) - [key (..default_start (..watch_events (..also (try.else ..none ?concern) - the_concern)) - watcher - path)] - (do async.monad - [_ (stm.commit! (stm.update (dictionary.has path [the_concern key]) tracker))] - (in {try.#Success []}))))) - (def: (concern path) - (do async.monad - [@tracker (stm.commit! (stm.read tracker))] - (case (dictionary.value path @tracker) - {.#Some [it key]} - (in {try.#Success it}) - - {.#None} - (in (exception.except ..not_being_watched [path]))))) - (def: stop stop) - (def: (poll _) - (async.future (..default_poll watcher))) - ))))) + .let [tracker (stm.var (is (Dictionary //.Path [Concern java/nio/file/WatchKey]) + (dictionary.empty text.hash))) + + stop (is (-> //.Path (Async (Try Concern))) + (function (_ path) + (do [! async.monad] + [@tracker (stm.commit! (stm.read tracker))] + (case (dictionary.value path @tracker) + {.#Some [the_concern key]} + (do ! + [_ (async.future + (java/nio/file/WatchKey::cancel key)) + _ (stm.commit! (stm.update (dictionary.lacks path) tracker))] + (in {try.#Success the_concern})) + + {.#None} + (in (exception.except ..not_being_watched [path]))))))]] + (in (is (Watcher Async) + (implementation + (def: (start the_concern path) + (do async.monad + [?concern (stop path)] + (do (try.with async.monad) + [key (..default_start (..watch_events (..also (try.else ..none ?concern) + the_concern)) + watcher + path)] + (do async.monad + [_ (stm.commit! (stm.update (dictionary.has path [the_concern key]) tracker))] + (in {try.#Success []}))))) + (def: (concern path) + (do async.monad + [@tracker (stm.commit! (stm.read tracker))] + (case (dictionary.value path @tracker) + {.#Some [it key]} + (in {try.#Success it}) + + {.#None} + (in (exception.except ..not_being_watched [path]))))) + (def: stop stop) + (def: (poll _) + (async.future (..default_poll watcher))) + ))))) )] (for @.old (as_is <jvm>) @.jvm (as_is <jvm>) |