refactor loadrequest.
This commit is contained in:
parent
64830059d7
commit
9966718e9c
@ -944,7 +944,7 @@ Pool.prototype._createPeer = function _createPeer(options) {
|
||||
item = items[i];
|
||||
req = self.request.map[item.hash];
|
||||
if (req && req.peer === peer)
|
||||
req.finish();
|
||||
req.finish(new Error('Not found.'));
|
||||
}
|
||||
});
|
||||
|
||||
@ -1619,7 +1619,7 @@ Pool.prototype._sendRequests = function _sendRequests(peer) {
|
||||
*/
|
||||
|
||||
Pool.prototype.fulfill = function fulfill(hash) {
|
||||
var i, item;
|
||||
var item;
|
||||
|
||||
if (hash.hash)
|
||||
hash = hash.hash('hex');
|
||||
@ -1630,9 +1630,6 @@ Pool.prototype.fulfill = function fulfill(hash) {
|
||||
|
||||
item.finish();
|
||||
|
||||
for (i = 0; i < item.callback.length; i++)
|
||||
item.callback[i]();
|
||||
|
||||
return item;
|
||||
};
|
||||
|
||||
@ -2050,8 +2047,8 @@ LoadRequest.prototype.start = function start() {
|
||||
* Remove from queue and map. Clear timeout.
|
||||
*/
|
||||
|
||||
LoadRequest.prototype.finish = function finish() {
|
||||
var index;
|
||||
LoadRequest.prototype.finish = function finish(err) {
|
||||
var i;
|
||||
|
||||
if (this.pool.request.map[this.hash]) {
|
||||
delete this.pool.request.map[this.hash];
|
||||
@ -2076,6 +2073,9 @@ LoadRequest.prototype.finish = function finish() {
|
||||
clearTimeout(this.timeout);
|
||||
delete this.timeout;
|
||||
}
|
||||
|
||||
for (i = 0; i < this.callback.length; i++)
|
||||
this.callback[i](err);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user