pool: refactor.
This commit is contained in:
parent
b0ee614432
commit
1e027220c3
@ -1294,47 +1294,6 @@ Pool.prototype._request = function _request(peer, type, hash, options, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
function LoadRequest(pool, peer, type, hash, cb) {
|
||||
this.pool = pool;
|
||||
this.peer = peer;
|
||||
this.type = type;
|
||||
this.hash = hash;
|
||||
this.cb = [];
|
||||
|
||||
if (cb)
|
||||
this.cb.push(cb);
|
||||
|
||||
this._finish = this.finish.bind(this);
|
||||
|
||||
this.timeout = setTimeout(this._finish, this.pool.requestTimeout);
|
||||
this.peer.on('close', this._finish);
|
||||
|
||||
this.pool.request.active++;
|
||||
|
||||
assert(!this.pool.request.map[this.hash]);
|
||||
this.pool.request.map[this.hash] = this;
|
||||
}
|
||||
|
||||
LoadRequest.prototype.finish = function finish() {
|
||||
var index;
|
||||
|
||||
if (this.pool.request.map[this.hash]) {
|
||||
delete this.pool.request.map[this.hash];
|
||||
this.pool.request.active--;
|
||||
}
|
||||
|
||||
index = this.peer._queue.indexOf(this);
|
||||
if (index !== -1)
|
||||
this.peer._queue.splice(index, 1);
|
||||
|
||||
this.peer.removeListener('close', this._finish);
|
||||
|
||||
if (this.timeout != null) {
|
||||
clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
};
|
||||
|
||||
Pool.prototype._response = function _response(hash) {
|
||||
var hash;
|
||||
|
||||
@ -1710,6 +1669,51 @@ Pool.prototype.isMisbehaving = function isMisbehaving(host) {
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* LoadRequest
|
||||
*/
|
||||
|
||||
function LoadRequest(pool, peer, type, hash, cb) {
|
||||
this.pool = pool;
|
||||
this.peer = peer;
|
||||
this.type = type;
|
||||
this.hash = hash;
|
||||
this.cb = [];
|
||||
|
||||
if (cb)
|
||||
this.cb.push(cb);
|
||||
|
||||
this._finish = this.finish.bind(this);
|
||||
|
||||
this.timeout = setTimeout(this._finish, this.pool.requestTimeout);
|
||||
this.peer.on('close', this._finish);
|
||||
|
||||
this.pool.request.active++;
|
||||
|
||||
assert(!this.pool.request.map[this.hash]);
|
||||
this.pool.request.map[this.hash] = this;
|
||||
}
|
||||
|
||||
LoadRequest.prototype.finish = function finish() {
|
||||
var index;
|
||||
|
||||
if (this.pool.request.map[this.hash]) {
|
||||
delete this.pool.request.map[this.hash];
|
||||
this.pool.request.active--;
|
||||
}
|
||||
|
||||
index = this.peer._queue.indexOf(this);
|
||||
if (index !== -1)
|
||||
this.peer._queue.splice(index, 1);
|
||||
|
||||
this.peer.removeListener('close', this._finish);
|
||||
|
||||
if (this.timeout != null) {
|
||||
clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user