Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on('created') event is triggered twice #63

Open
hugohil opened this issue Sep 24, 2014 · 6 comments
Open

on('created') event is triggered twice #63

hugohil opened this issue Sep 24, 2014 · 6 comments

Comments

@hugohil
Copy link

hugohil commented Sep 24, 2014

Hi there !
Like the title say so, my "ceated" event gets triggered twice and I can't seem to figure out why.
Here is a sample code:

var root = "/home/me/myfolder",
    watch = require('watch');

watch.createMonitor(root, function (monitor) {
    monitor.on("created", function (path, stat) {
        console.log("created", path);
    });
});

When a new document is created, I see the log print twice.
Has anyone an idea on how could I fix this ?

@qlqllu
Copy link

qlqllu commented Jan 27, 2015

+1

@qlqllu
Copy link

qlqllu commented Jan 27, 2015

I use setTimeout to avoid twice events.

@matthewwilson
Copy link

I'm seeing the same issue. How can I use setTimeout to resolve it?

@qlqllu
Copy link

qlqllu commented May 25, 2015

@MatthewCodes This is the issue in node repo: nodejs/node-v0.x-archive#1970

I create an array to store all changed files, and I filter out duplicated files by using changedFiles.indexOf().
But in timeout callback, I clear the array. So, you need to set an appropriate timeout value.

@willfarrell
Copy link

+1

I'm using it to import xml files into a db. I used a que for the new files and then removed the duplicate before triggering the import that has throttling to limit the amount of memory used. Partial code below to give you an idea.

que.push(path);
que = uniqueArr(que); // return array of unique values
setTimeout(function() {
    _import();
}, timeout);
...
function _import () {
    if (!que.length || process_count >= process_max) { return; }
    var file = que.shift();
    ... // process file
    _import ();
}

@martinlevesque
Copy link

same issue with watch.watchTree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants