more code cleanup.
This commit is contained in:
parent
9c64b62078
commit
f24d4aa938
@ -64,8 +64,6 @@ function Pool(node, options) {
|
|||||||
|
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
this.synced = false;
|
this.synced = false;
|
||||||
this.busy = false;
|
|
||||||
this.jobs = [];
|
|
||||||
this._scheduled = false;
|
this._scheduled = false;
|
||||||
|
|
||||||
this.load = {
|
this.load = {
|
||||||
@ -233,50 +231,12 @@ Pool.prototype._init = function _init() {
|
|||||||
this.startServer();
|
this.startServer();
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._lock = function _lock(func, args, force) {
|
|
||||||
var self = this;
|
|
||||||
var called;
|
|
||||||
|
|
||||||
if (force) {
|
|
||||||
assert(this.busy);
|
|
||||||
return function unlock() {
|
|
||||||
assert(!called);
|
|
||||||
called = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.busy) {
|
|
||||||
this.jobs.push([func, args]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.busy = true;
|
|
||||||
|
|
||||||
return function unlock() {
|
|
||||||
var item;
|
|
||||||
|
|
||||||
assert(!called);
|
|
||||||
called = true;
|
|
||||||
|
|
||||||
self.busy = false;
|
|
||||||
|
|
||||||
if (self.jobs.length === 0) {
|
|
||||||
self.emit('flush');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item = self.jobs.shift();
|
|
||||||
item[0].apply(self, item[1]);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -284,7 +244,6 @@ Pool.prototype.getBlocks = function getBlocks(peer, top, stop, callback) {
|
|||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callback) {
|
Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callback) {
|
||||||
@ -294,8 +253,7 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callbac
|
|||||||
|
|
||||||
assert(orphan);
|
assert(orphan);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -323,7 +281,6 @@ Pool.prototype.resolveOrphan = function resolveOrphan(peer, top, orphan, callbac
|
|||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
||||||
@ -331,8 +288,7 @@ Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
|||||||
|
|
||||||
callback = utils.ensure(callback);
|
callback = utils.ensure(callback);
|
||||||
|
|
||||||
this.chain.onFlush(function() {
|
this.chain.getLocator(top, function(err, locator) {
|
||||||
self.chain.getLocator(top, function(err, locator) {
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
@ -340,7 +296,6 @@ Pool.prototype.getHeaders = function getHeaders(peer, top, stop, callback) {
|
|||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.startServer = function startServer() {
|
Pool.prototype.startServer = function startServer() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user