mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
allow Request.request(callback)
This commit is contained in:
@@ -39,8 +39,9 @@ function Request(remote, command) {
|
|||||||
util.inherits(Request, EventEmitter);
|
util.inherits(Request, EventEmitter);
|
||||||
|
|
||||||
// Send the request to a remote.
|
// Send the request to a remote.
|
||||||
Request.prototype.request = function(servers, callback) {
|
Request.prototype.request = function(servers, callback_) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
const callback = typeof servers === 'function' ? servers : callback_;
|
||||||
|
|
||||||
this.emit('before');
|
this.emit('before');
|
||||||
this.callback(callback);
|
this.callback(callback);
|
||||||
@@ -247,7 +248,9 @@ Request.prototype.callback = function(callback, successEvent, errorEvent) {
|
|||||||
|
|
||||||
this.once(this.successEvent, requestSuccess);
|
this.once(this.successEvent, requestSuccess);
|
||||||
this.once(this.errorEvent, requestError);
|
this.once(this.errorEvent, requestError);
|
||||||
|
if (!this.requested) {
|
||||||
this.request();
|
this.request();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -672,7 +672,6 @@ Server.prototype._handleResponse = function(message) {
|
|||||||
const responseEvent = 'response_' + command;
|
const responseEvent = 'response_' + command;
|
||||||
|
|
||||||
request.emit('success', result);
|
request.emit('success', result);
|
||||||
request.emit('response', result);
|
|
||||||
|
|
||||||
[this, this._remote].forEach(function(emitter) {
|
[this, this._remote].forEach(function(emitter) {
|
||||||
emitter.emit(responseEvent, result, request, message);
|
emitter.emit(responseEvent, result, request, message);
|
||||||
@@ -687,8 +686,8 @@ Server.prototype._handleResponse = function(message) {
|
|||||||
error_message: 'Remote reported an error.',
|
error_message: 'Remote reported an error.',
|
||||||
remote: message
|
remote: message
|
||||||
});
|
});
|
||||||
request.emit('response');
|
|
||||||
}
|
}
|
||||||
|
request.emit('response', message);
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype._handlePathFind = function(message) {
|
Server.prototype._handlePathFind = function(message) {
|
||||||
|
|||||||
Reference in New Issue
Block a user