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

add barrier.abort (issue #8) #15

Open
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+22 −1
Diff settings

Always

Just for now

Next

add barrier.abort

  • Loading branch information...
fkuo committed Jan 29, 2014
commit a132569bb636b5f91c12174ca11bd9ad67d446ed
View
@@ -434,6 +434,7 @@ function Barrier(args)
this.recent = [];
}
this.aborted = {};
this.pending = {};
this.scheduled = false;
}
@@ -444,14 +445,22 @@ Barrier.prototype.start = function (name)
{
mod_assert.ok(!this.pending.hasOwnProperty(name),
'operation "' + name + '" is already pending');
if (this.aborted.hasOwnProperty(name))
delete this.aborted[name];
this.pending[name] = Date.now();
};
Barrier.prototype.done = function (name)
{
mod_assert.ok(this.pending.hasOwnProperty(name),
mod_assert.ok(this.pending.hasOwnProperty(name) ||
this.aborted.hasOwnProperty(name),
'operation "' + name + '" is not pending');
if (this.aborted.hasOwnProperty(name))
return;
if (this.recent) {
this.recent.push({
'name': name,
@@ -494,3 +503,15 @@ Barrier.prototype.done = function (name)
self.emit('drain');
});
};
Barrier.prototype.abort = function (err)
{
var self = this;
var now = Date.now();
Object.keys(this.pending).forEach(function (name) {
self.aborted[name] = now;
});
this.pending = {};
this.emit('drain', err);
};
ProTip! Use n and p to navigate between commits in a pull request.