Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
close when process is killed (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 12, 2017
1 parent 7f9d99a commit 37a7151
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,24 @@ export default function watch ( rollup, options ) {
// build on next tick, so consumers can listen for BUILD_START
process.nextTick( build );

watcher.close = () => {
function close () {
if ( closed ) return;
for ( const fw of filewatchers.values() ) {
fw.close();
}
closed = true;
};
}

watcher.close = close;

// ctrl-c
process.on('SIGINT', close);

// killall node
process.on('SIGTERM', close);

// on error
process.on('uncaughtException', close);

return watcher;
}

0 comments on commit 37a7151

Please sign in to comment.