I am 'Q-ifying' a nodejs class i have written for communication with an XMPP device. I have done all methods except this one, and i really could use some help.
The result i would like to have is that the following function would become chainable using the 'Q' library. Since this function calls itself in case the XMPP client is not yet connected or disconnected, i am kinda stuck.
Client.prototype._send = function(command, body) {
switch(this._state) {
case 'disconnected':
// wait for reconnect and try again, also issue connect
this.once('reconnect',
(function() {
this._send(command, body);
}).bind(this));
this.connect(true);
return;
case 'connecting':
// wait for reconnect and try again
this.once('reconnect',
(function() {
this._send(command, body);
}).bind(this));
return;
}
var iq = new IQ().command(command);
if (body)
iq.body(body);
this.xmpp.send(iq);
};
Any tips on how to make it something like this?
Client.prototype._send = function(command, body) {
return Q.Promise((function(resolve, reject, notify) {
// ...
}).bind(this));
};
Aucun commentaire:
Enregistrer un commentaire