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

not updating race condition fix #249

Merged
4 commits merged into from
Jul 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function watchify (b, opts) {
var delay = typeof opts.delay === 'number' ? opts.delay : 600;
var changingDeps = {};
var pending = false;
var updating = false;

var wopts = {persistent: true};
if (opts.ignoreWatch) {
Expand Down Expand Up @@ -93,14 +94,19 @@ function watchify (b, opts) {
watchFile(mfile, dep);
});
});
b.on('bundle', function (bundle) {
bundle.on('error', onend);
bundle.on('end', onend);
function onend () { updating = false }
});

function watchFile (file, dep) {
dep = dep || file;
if (ignored) {
if (!ignoredFiles.hasOwnProperty(file)) {
ignoredFiles[file] = anymatch(ignored, file);
}
if (ignoredFiles[file]) return;
if (!ignoredFiles.hasOwnProperty(file)) {
ignoredFiles[file] = anymatch(ignored, file);
}
if (ignoredFiles[file]) return;
}
if (!fwatchers[file]) fwatchers[file] = [];
if (!fwatcherFiles[file]) fwatcherFiles[file] = [];
Expand All @@ -119,20 +125,25 @@ function watchify (b, opts) {
function invalidate (id) {
if (cache) delete cache[id];
if (pkgcache) delete pkgcache[id];
changingDeps[id] = true;
if (updating) return;

if (fwatchers[id]) {
fwatchers[id].forEach(function (w) {
w.close();
});
delete fwatchers[id];
delete fwatcherFiles[id];
}
changingDeps[id] = true

// wait for the disk/editor to quiet down first:
if (!pending) setTimeout(function () {
pending = false;
b.emit('update', Object.keys(changingDeps));
changingDeps = {};
if (!updating) {
updating = true;
b.emit('update', Object.keys(changingDeps));
changingDeps = {};
}
}, delay);
pending = true;
}
Expand Down