Skip to content

Commit

Permalink
📣 Kill worker when already running fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
VandeurenGlenn committed May 14, 2017
1 parent 3813136 commit 26e0023
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const logger = require('backed-logger');
const time = () => {
return new Date().toLocaleTimeString();
};
let worker;

/**
* @extends EventEmitter
Expand Down Expand Up @@ -62,7 +63,11 @@ class Watcher extends EventEmitter {
}

runWorker(task, config) {
let worker;
if (this.busy) {
worker.kill();
this.busy = false;
}
this.busy = true;
worker = fork(path.join(__dirname, 'workers/watcher-worker.js'));
worker.on('message', message => {
if (message === 'done') {
Expand All @@ -71,6 +76,8 @@ class Watcher extends EventEmitter {
}
logger.log(`[${time()}] ${logger._chalk('Reloading browser', 'cyan')}`);
this.emit(message);
worker.kill();
this.busy = false;
});
worker.send({task: task, config: config});
}
Expand Down

0 comments on commit 26e0023

Please sign in to comment.