locker: refactor.
This commit is contained in:
parent
a2d6ed56e7
commit
5a353d1592
@ -73,10 +73,10 @@ Locker.prototype.hasPending = function hasPending(key) {
|
||||
|
||||
Locker.prototype.lock = function lock(arg1, arg2) {
|
||||
var self = this;
|
||||
var force, object;
|
||||
var force, item;
|
||||
|
||||
if (this.add) {
|
||||
object = arg1;
|
||||
item = arg1;
|
||||
force = arg2;
|
||||
} else {
|
||||
force = arg1;
|
||||
@ -91,13 +91,13 @@ Locker.prototype.lock = function lock(arg1, arg2) {
|
||||
}
|
||||
|
||||
if (this.busy) {
|
||||
if (object) {
|
||||
this.pending.push(object);
|
||||
this.pendingMap[object.hash('hex')] = true;
|
||||
if (item) {
|
||||
this.pending.push(item);
|
||||
this.pendingMap[item.hash('hex')] = true;
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
self.jobs.push(new Job(resolve, reject, object));
|
||||
self.jobs.push(new Job(resolve, reject, item));
|
||||
});
|
||||
}
|
||||
|
||||
@ -125,13 +125,13 @@ Locker.prototype.unlock = function unlock() {
|
||||
job = this.jobs.shift();
|
||||
|
||||
if (this.destroyed) {
|
||||
job.reject(new Error('Locker is destroyed.'));
|
||||
job.reject(new Error('Locker was destroyed.'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (job.object) {
|
||||
assert(job.object === this.pending.shift());
|
||||
delete this.pendingMap[job.object.hash('hex')];
|
||||
if (job.item) {
|
||||
assert(job.item === this.pending.shift());
|
||||
delete this.pendingMap[job.item.hash('hex')];
|
||||
}
|
||||
|
||||
this.busy = true;
|
||||
@ -258,7 +258,7 @@ MappedLock.prototype.unlock = function unlock(key) {
|
||||
delete self.jobs[key];
|
||||
|
||||
if (self.destroyed) {
|
||||
job.reject(new Error('Locker is destroyed.'));
|
||||
job.reject(new Error('Locker was destroyed.'));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -282,13 +282,13 @@ MappedLock.prototype.destroy = function destroy() {
|
||||
* @constructor
|
||||
* @param {Function} resolve
|
||||
* @param {Function} reject
|
||||
* @param {Object?} object
|
||||
* @param {Object?} item
|
||||
*/
|
||||
|
||||
function Job(resolve, reject, object) {
|
||||
function Job(resolve, reject, item) {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
this.object = object || null;
|
||||
this.item = item || null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user