diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/world/file/watch.lux | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/stdlib/source/lux/world/file/watch.lux b/stdlib/source/lux/world/file/watch.lux index 5d995bbd4..1a59721d4 100644 --- a/stdlib/source/lux/world/file/watch.lux +++ b/stdlib/source/lux/world/file/watch.lux @@ -90,164 +90,164 @@ (: (-> [] (! (Try (List [//.Path Concern])))) poll)) -(exception: #export (not-being-watched {path //.Path}) +(exception: #export (not_being_watched {path //.Path}) (exception.report ["Path" (%.text path)])) -(type: File-Tracker +(type: File_Tracker (Dictionary //.Path [(//.File Promise) Instant])) -(type: Directory-Tracker - (Dictionary //.Path [Concern (//.Directory Promise) File-Tracker])) +(type: Directory_Tracker + (Dictionary //.Path [Concern (//.Directory Promise) File_Tracker])) -(def: (update-watch! new-concern path tracker) - (-> Concern //.Path (Var Directory-Tracker) (STM Bit)) +(def: (update_watch! new_concern path tracker) + (-> Concern //.Path (Var Directory_Tracker) (STM Bit)) (do {! stm.monad} [@tracker (stm.read tracker)] (case (dictionary.get path @tracker) - (#.Some [old-concern file last-modified]) + (#.Some [old_concern file last_modified]) (do ! - [_ (stm.update (dictionary.put path [new-concern file last-modified]) tracker)] + [_ (stm.update (dictionary.put path [new_concern file last_modified]) tracker)] (wrap true)) #.None (wrap false)))) -(def: (file-tracker fs directory) - (-> (//.System Promise) (//.Directory Promise) (Promise (Try File-Tracker))) +(def: (file_tracker fs directory) + (-> (//.System Promise) (//.Directory Promise) (Promise (Try File_Tracker))) (do {! (try.with promise.monad)} [files (!.use (\ directory files) [])] (monad.fold ! (function (_ file tracker) (do ! - [last-modified (!.use (\ file last-modified) [])] + [last_modified (!.use (\ file last_modified) [])] (wrap (dictionary.put (!.use (\ file path) []) - [file last-modified] + [file last_modified] tracker)))) - (: File-Tracker + (: File_Tracker (dictionary.new text.hash)) files))) -(def: (poll-files directory file-tracker) - (-> (//.Directory Promise) File-Tracker (Promise (Try (List [//.Path (//.File Promise) Instant])))) +(def: (poll_files directory file_tracker) + (-> (//.Directory Promise) File_Tracker (Promise (Try (List [//.Path (//.File Promise) Instant])))) (do {! (try.with promise.monad)} [files (!.use (\ directory files) [])] (monad.map ! (function (_ file) (do ! - [last-modified (!.use (\ file last-modified) [])] - (wrap [(!.use (\ file path) []) file last-modified]))) + [last_modified (!.use (\ file last_modified) [])] + (wrap [(!.use (\ file path) []) file last_modified]))) files))) -(def: (poll-directory-changes [path [concern directory file-tracker]]) - (-> [//.Path [Concern (//.Directory Promise) File-Tracker]] - (Promise (Try [[//.Path [Concern (//.Directory Promise) File-Tracker]] +(def: (poll_directory_changes [path [concern directory file_tracker]]) + (-> [//.Path [Concern (//.Directory Promise) File_Tracker]] + (Promise (Try [[//.Path [Concern (//.Directory Promise) File_Tracker]] [(List [//.Path (//.File Promise) Instant]) (List [//.Path Instant Instant]) (List [//.Path])]]))) (do {! (try.with promise.monad)} - [current-files (..poll-files directory file-tracker) + [current_files (..poll_files directory file_tracker) #let [creations (if (..creation? concern) - (list.filter (|>> product.left (dictionary.key? file-tracker) not) - current-files) + (list.filter (|>> product.left (dictionary.key? file_tracker) not) + current_files) (list)) - available (|> current-files + available (|> current_files (list\map product.left) - (set.from-list text.hash)) + (set.from_list text.hash)) deletions (if (..deletion? concern) - (|> (dictionary.entries file-tracker) + (|> (dictionary.entries file_tracker) (list\map product.left) (list.filter (|>> (set.member? available) not))) (list)) - modifications (list.all (function (_ [path file current-modification]) + modifications (list.all (function (_ [path file current_modification]) (do maybe.monad - [[_ previous-modification] (dictionary.get path file-tracker)] - (wrap [path previous-modification current-modification]))) - current-files)]] + [[_ previous_modification] (dictionary.get path file_tracker)] + (wrap [path previous_modification current_modification]))) + current_files)]] (wrap [[path [concern directory - (let [with-deletions (list\fold dictionary.remove file-tracker deletions) - with-creations (list\fold (function (_ [path file last-modified] tracker) - (dictionary.put path [file last-modified] tracker)) - with-deletions + (let [with_deletions (list\fold dictionary.remove file_tracker deletions) + with_creations (list\fold (function (_ [path file last_modified] tracker) + (dictionary.put path [file last_modified] tracker)) + with_deletions creations) - with-modifications (list\fold (function (_ [path previous-modification current-modification] tracker) + with_modifications (list\fold (function (_ [path previous_modification current_modification] tracker) (dictionary.update path (function (_ [file _]) - [file current-modification]) + [file current_modification]) tracker)) - with-creations + with_creations modifications)] - with-modifications)]] + with_modifications)]] [creations modifications deletions]]))) (def: #export (polling fs) (-> (//.System Promise) (Watcher Promise)) - (let [tracker (: (Var Directory-Tracker) + (let [tracker (: (Var Directory_Tracker) (stm.var (dictionary.new text.hash)))] (structure - (def: (start new-concern path) + (def: (start new_concern path) (do {! promise.monad} - [updated? (stm.commit (..update-watch! new-concern path tracker))] + [updated? (stm.commit (..update_watch! new_concern path tracker))] (if updated? (wrap (#try.Success [])) (do (try.with !) [directory (!.use (\ fs directory) path) - file-tracker (..file-tracker fs directory)] + file_tracker (..file_tracker fs directory)] (do ! - [_ (stm.commit (stm.update (dictionary.put path [new-concern directory file-tracker]) tracker))] + [_ (stm.commit (stm.update (dictionary.put path [new_concern directory file_tracker]) tracker))] (wrap (#try.Success []))))))) (def: (concern path) (stm.commit (do stm.monad [@tracker (stm.read tracker)] (wrap (case (dictionary.get path @tracker) - (#.Some [concern directory file-tracker]) + (#.Some [concern directory file_tracker]) (#try.Success concern) #.None - (exception.throw ..not-being-watched [path])))))) + (exception.throw ..not_being_watched [path])))))) (def: (stop path) (stm.commit (do {! stm.monad} [@tracker (stm.read tracker)] (case (dictionary.get path @tracker) - (#.Some [concern directory file-tracker]) + (#.Some [concern directory file_tracker]) (do ! [_ (stm.update (dictionary.remove path) tracker)] (wrap (#try.Success concern))) #.None - (wrap (exception.throw ..not-being-watched [path])))))) + (wrap (exception.throw ..not_being_watched [path])))))) (def: (poll _) (do promise.monad [@tracker (stm.commit (stm.read tracker))] (do {! (try.with promise.monad)} [changes (|> @tracker dictionary.entries - (monad.map ! ..poll-directory-changes)) + (monad.map ! ..poll_directory_changes)) _ (do promise.monad [_ (stm.commit (stm.write (|> changes (list\map product.left) - (dictionary.from-list text.hash)) + (dictionary.from_list text.hash)) tracker))] (wrap (#try.Success []))) #let [[creations modifications deletions] (list\fold (function (_ [_ [creations modifications deletions]] - [all-creations all-modifications all-deletions]) - [(list\compose creations all-creations) - (list\compose modifications all-modifications) - (list\compose deletions all-deletions)]) + [all_creations all_modifications all_deletions]) + [(list\compose creations all_creations) + (list\compose modifications all_modifications) + (list\compose deletions all_deletions)]) [(list) (list) (list)] changes)]] (wrap ($_ list\compose - (list\map (function (_ [path file last-modification]) [path ..creation]) creations) + (list\map (function (_ [path file last_modification]) [path ..creation]) creations) (|> modifications - (list.filter (function (_ [path previous-modification current-modification]) - (not (instant\= previous-modification current-modification)))) - (list\map (function (_ [path previous-modification current-modification]) + (list.filter (function (_ [path previous_modification current_modification]) + (not (instant\= previous_modification current_modification)))) + (list\map (function (_ [path previous_modification current_modification]) [path ..modification]))) (list\map (function (_ path) [path ..deletion]) deletions) ))))) @@ -259,7 +259,7 @@ [fs (..polling fs)])) -(with-expansions [<jvm> (as-is (import: java/lang/Object) +(with_expansions [<jvm> (as_is (import: java/lang/Object) (import: java/lang/String) @@ -298,7 +298,7 @@ (#static ENTRY_MODIFY (java/nio/file/WatchEvent$Kind java/nio/file/Path)) (#static ENTRY_DELETE (java/nio/file/WatchEvent$Kind java/nio/file/Path))]) - (def: (default\\event-concern event) + (def: (default\\event_concern event) (All [a] (-> (java/nio/file/WatchEvent a) Concern)) (let [kind (:coerce (java/nio/file/WatchEvent$Kind java/nio/file/Path) @@ -326,11 +326,11 @@ (watchable [] java/nio/file/Watchable) (pollEvents [] #io (java/util/List (java/nio/file/WatchEvent ?)))]) - (def: default\\key-concern + (def: default\\key_concern (-> java/nio/file/WatchKey (IO Concern)) (|>> java/nio/file/WatchKey::pollEvents (\ io.monad map (|>> ..default\\list - (list\map default\\event-concern) + (list\map default\\event_concern) (list\fold ..also ..none))))) (import: java/nio/file/WatchService @@ -350,14 +350,14 @@ (new [java/lang/String]) (toPath [] java/nio/file/Path)]) - (type: Watch-Event + (type: Watch_Event (java/nio/file/WatchEvent$Kind java/lang/Object)) - (def: (default\\start watch-events watcher path) - (-> (List Watch-Event) java/nio/file/WatchService //.Path (Promise (Try java/nio/file/WatchKey))) + (def: (default\\start watch_events watcher path) + (-> (List Watch_Event) java/nio/file/WatchService //.Path (Promise (Try java/nio/file/WatchKey))) (promise.future (java/nio/file/Path::register watcher - (array.from-list watch-events) + (array.from_list watch_events) (|> path java/io/File::new java/io/File::toPath)))) (def: (default\\poll watcher) @@ -377,7 +377,7 @@ (:coerce java/nio/file/Path) java/nio/file/Path::toString (:coerce //.Path))] - concern (..default\\key-concern key)] + concern (..default\\key_concern key)] (recur (#.Cons [path concern] output))) (recur output))) @@ -385,17 +385,17 @@ #.None (wrap output))))) - (def: (watch-events concern) - (-> Concern (List Watch-Event)) + (def: (watch_events concern) + (-> Concern (List Watch_Event)) ($_ list\compose (if (..creation? concern) - (list (:coerce Watch-Event (java/nio/file/StandardWatchEventKinds::ENTRY_CREATE))) + (list (:coerce Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_CREATE))) (list)) (if (..modification? concern) - (list (:coerce Watch-Event (java/nio/file/StandardWatchEventKinds::ENTRY_MODIFY))) + (list (:coerce Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_MODIFY))) (list)) (if (..deletion? concern) - (list (:coerce Watch-Event (java/nio/file/StandardWatchEventKinds::ENTRY_DELETE))) + (list (:coerce Watch_Event (java/nio/file/StandardWatchEventKinds::ENTRY_DELETE))) (list)) )) @@ -420,14 +420,14 @@ (wrap (#try.Success concern))) #.None - (wrap (exception.throw ..not-being-watched [path]))))))]] + (wrap (exception.throw ..not_being_watched [path]))))))]] (wrap (: (Watcher Promise) (structure (def: (start concern path) (do promise.monad [?concern (stop path)] (do (try.with promise.monad) - [key (..default\\start (..watch-events (..also (try.default ..none ?concern) + [key (..default\\start (..watch_events (..also (try.default ..none ?concern) concern)) watcher path)] @@ -442,11 +442,11 @@ (wrap (#try.Success concern)) #.None - (wrap (exception.throw ..not-being-watched [path]))))) + (wrap (exception.throw ..not_being_watched [path]))))) (def: stop stop) (def: (poll _) (promise.future (..default\\poll watcher))) ))))) )] - (for {@.old (as-is <jvm>) - @.jvm (as-is <jvm>)})) + (for {@.old (as_is <jvm>) + @.jvm (as_is <jvm>)})) |