Browse files

ability to programmatically stop watching

  • Loading branch information...
1 parent d0e4201 commit 1300d55aabc589352ce3aff4e5d341fda7981b62 @andrewrk committed Jul 24, 2012
Showing with 10 additions and 7 deletions.
  1. +2 −2 src/jspackage.co
  2. +8 −5 src/watch.co
View
4 src/jspackage.co
@@ -160,15 +160,15 @@ export const compile = !(options, cb) ->
return
(err, dependency_chain) <-! resolveDependencyChain(root)
if watching
- watchFilesOnce (dep.path for dep of dependency_chain), !->
+ const closer = watchFilesOnce (dep.path for dep of dependency_chain), !->
compile options, cb
if err
cb(err)
else if collect_err
cb(collect_err)
else
const output = (dep.compiled_js for dep of dependency_chain).join("\n")
- cb(null, output)
+ cb(null, output, closer)
export const extensions =
'.coffee':
View
13 src/watch.co
@@ -12,18 +12,21 @@ const watchFile = fs.watch or watchFileFallback
# when any one of these files change, call callback
# and stop watching
-export const watchFilesOnce = !(files, cb) ->
- const watchers = []
+export const watchFilesOnce = (files, cb) ->
+ watchers = []
+ const close = !->
+ watcher.close! for watcher of watchers
+ watchers := []
const doCallback = !(event) ->
if event is \change
- watcher.close! for watcher of watchers
+ close!
cb!
for file of files
try
watcher = fs.watch(file, doCallback)
catch err
watcher = watchFileFallback(file, doCallback)
- watchers.push watcher
-
+ watchers.push(watcher)
+ {close}

0 comments on commit 1300d55

Please sign in to comment.