make sure that 'before' event emitted from Request only once

This commit is contained in:
Ivan Tivonenko
2015-09-28 03:00:59 +03:00
parent 87fdbc932f
commit ed3b04ed6f
2 changed files with 22 additions and 2 deletions

View File

@@ -44,13 +44,15 @@ Request.prototype.request = function(servers, callback_) {
const callback = typeof servers === 'function' ? servers : callback_;
this.emit('before');
const wasRequested = this.requested;
this.requested = true;
this.callback(callback);
if (this.requested) {
if (wasRequested) {
return this;
}
this.requested = true;
this.on('error', function() {});
this.emit('request', this.remote);