(.module: [lux #* [abstract ["." monad (#+ do)]] [control ["." try (#+ Try)] [concurrency ["." promise (#+ Promise)]]] [data [collection ["." list] ["." set]]] [world [program (#+ Program)] [shell (#+ Exit Shell)] [console (#+ Console)] ["." file ["." watch (#+ Watcher)]]]] ["." // #_ ["/#" // #_ [command (#+ Command)] ["#" profile] ["#." action] [dependency [resolution (#+ Resolution)]]]]) (def: (targets fs path) (-> (file.System Promise) file.Path (Promise (List file.Path))) (let [! promise.monad] (|> path (\ fs sub_directories) (\ ! map (|>> (try.default (list)) (monad.map ! (targets fs)))) (\ ! join) (\ ! map (|>> list.concat (list& path)))))) (def: #export delay Nat 1,000) (def: (pause delay) (-> Nat (Promise (Try Any))) (promise.delay delay (#try.Success []))) (def: #export (do! delay watcher command) (All [a] (-> Nat (Watcher Promise) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit a])) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Any])))) (function (_ console program fs shell resolution) (function (_ profile) (with_expansions [ ((command console program fs shell resolution) profile)] (do {! promise.monad} [targets (|> profile (get@ #///.sources) set.to_list (monad.map ! (..targets fs)) (\ ! map list.concat))] (do {! ///action.monad} [_ (monad.map ! (\ watcher start watch.modification) targets) _ ] (loop [_ []] (do ! [_ (..pause delay) events (\ watcher poll [])] (case events (#.Cons _) (do ! [_ ] (recur [])) #.Nil (recur []))))))))))