How to add Promise to event handler in javascript
问题 Now I want to wrap amqp with Promise Q, here are the codes Sender.prototype.createConnection_ = function () { var deferred = Q.defer(); this.con_ = amqp.createConnection( this.connectOpt_, this.implementOpt_ ); deferred.resolve( this.con_ ); return deferred.promise; } Sender.prototype.connectionReady_ = function() { var deferred = Q.defer(), self = this; self.con_.on('ready', function() { console.log('connection is ok now'); deferred.resolve(self.con_); }); return deferred.promise; } Sender