{"action":"closed","issue":{"url":"https://api.github.com/repos/kriskowal/q/issues/661","labels_url":"https://api.github.com/repos/kriskowal/q/issues/661/labels{/name}","comments_url":"https://api.github.com/repos/kriskowal/q/issues/661/comments","events_url":"https://api.github.com/repos/kriskowal/q/issues/661/events","html_url":"https://github.com/kriskowal/q/issues/661","id":60344316,"number":661,"title":"How to add Q in the event trigger function?","user":{"login":"richzw","id":1590890,"avatar_url":"https://avatars.githubusercontent.com/u/1590890?v=3","gravatar_id":"","url":"https://api.github.com/users/richzw","html_url":"https://github.com/richzw","followers_url":"https://api.github.com/users/richzw/followers","following_url":"https://api.github.com/users/richzw/following{/other_user}","gists_url":"https://api.github.com/users/richzw/gists{/gist_id}","starred_url":"https://api.github.com/users/richzw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richzw/subscriptions","organizations_url":"https://api.github.com/users/richzw/orgs","repos_url":"https://api.github.com/users/richzw/repos","events_url":"https://api.github.com/users/richzw/events{/privacy}","received_events_url":"https://api.github.com/users/richzw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/kriskowal/q/labels/community-help-welcome","name":"community-help-welcome","color":"5319e7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-09T13:42:16Z","updated_at":"2015-03-12T00:37:52Z","closed_at":"2015-03-12T00:37:52Z","body":"Now I want to wrap `amqp` with `q`, here are the codes.\r\n\r\n```javascript\r\nSender.prototype.createConnection_ = function () {\r\n    var deferred = Q.defer();\r\n    this.con_ = amqp.createConnection( this.connectOpt_, this.implementOpt_ );\r\n    deferred.resolve( this.con_ );\r\n\r\n    return deferred.promise;\r\n}\r\n\r\nSender.prototype.connectionReady_ = function() {\r\n    var deferred = Q.defer(),\r\n      self = this;\r\n\r\n    self.con_.on('ready', function() {\r\n        console.log('connection is ok now');\r\n        deferred.resolve(self.con_);\r\n    });\r\n    return deferred.promise;\r\n}\r\n\r\nSender.prototype.createExchange_ = function() {\r\n    var deferred = Q.defer(),\r\n      self = this;\r\n\r\n    this.con_.exchange( this.exchangeName_, this.exchangeOpt_, function ( ex ) {\r\n        self.ex_ = ex;\r\n        deferred.resolve(self.ex_);\r\n    });\r\n    return deferred.promise;\r\n}\r\n\r\nSender.prototype.exchangeReady_ = function() {\r\n    var deferred = Q.defer(),\r\n      self = this;\r\n\r\n    this.ex_.on('open', function() {\r\n        console.log('Sender: exchange opened');\r\n        deferred.resolve(this.ex_);\r\n    });\r\n    return deferred.promise;\r\n}\r\n\r\nSender.prototype.connect_ = function() {\r\n    var self = this;\r\n    return self.createConnection_()\r\n            .then( self.connectionReady_() )\r\n            .then( self.createExchange_() )\r\n            .then( self.exchangeReady_() )\r\n            .catch( function(err) {\r\n                console.info( err );\r\n            });\r\n}\r\n```\r\n\r\nWhen I want to invoke `connect_`, there is one error show that `this.ex_` is `null` in the `exchangeReady_` function.\r\n\r\nI want to how to add `Q` in the event `open` function ?"}}