Skip to content

Instantly share code, notes, and snippets.

@hexparrot
Created November 12, 2015 18:40
Show Gist options
  • Save hexparrot/fc431960d08749d9061b to your computer and use it in GitHub Desktop.
Save hexparrot/fc431960d08749d9061b to your computer and use it in GitHub Desktop.
Fireworm broadcasts events twice
var fireworm = require('fireworm')
var path = require('path')
var fs = require('fs')
var mkdirSync = function (path) {
try {
fs.mkdirSync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
}
}
var dir = path.join(process.env.HOME, 'testfw')
mkdirSync(dir)
var fw = fireworm(dir);
fw.add('**/new.file')
fw
.on('add', function(fp){
console.log('added', fp)
})
.on('remove', function(fp) {
console.log('removed', fp)
})
setTimeout(function() {
var newdir = path.join(dir, '1')
mkdirSync(newdir)
fs.writeFileSync(path.join(newdir, 'new.file'))
}, 1000)
setTimeout(function() {
var newdir = path.join(dir, '2')
mkdirSync(newdir)
fs.writeFileSync(path.join(newdir, 'new.file'))
}, 2000)
/*
mc@ubuntu:~/fw$ node fwtest.js
added /home/mc/testfw/1/new.file
added /home/mc/testfw/2/new.file
^C
mc@ubuntu:~/fw$ node fwtest.js
added /home/mc/testfw/1/new.file
added /home/mc/testfw/2/new.file
added /home/mc/testfw/1/new.file
added /home/mc/testfw/2/new.file
mc@ubuntu:~/fw$ node -v
v5.0.0
mc@ubuntu:~/fw$ npm -v
3.3.6
mc@ubuntu:~/fw$ uname -a
Linux ubuntu 4.2.0-17-generic #21-Ubuntu SMP Fri Oct 23 19:56:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment