{"action":"created","issue":{"url":"https://api.github.com/repos/cujojs/when/issues/426","labels_url":"https://api.github.com/repos/cujojs/when/issues/426/labels{/name}","comments_url":"https://api.github.com/repos/cujojs/when/issues/426/comments","events_url":"https://api.github.com/repos/cujojs/when/issues/426/events","html_url":"https://github.com/cujojs/when/issues/426","id":57129221,"number":426,"title":"Question: How to do this control flow","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":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-02-10T04:25:57Z","updated_at":"2015-03-31T00:48:16Z","closed_at":"2015-03-31T00:48:16Z","body":"Now I am learning how to write js codes with `when`. Here is my case, the `deliverMessage` function in `Sender` try to connect with amqp. If success, then call `publish_`. otherwise, call `reconnect_` to connect to amqp after 3 seconds. The codes are as following, \r\n\r\n```javascript\r\nSender.prototype.reconnect_ = function( err ) {\r\n\tconsole.error('MessageBus disconnected, attempting to reconnect' + err);\r\n\tthis.createFakeChannel_();\r\n\treturn setTimeout( this.deliverMessage.bind(this), 3000);\r\n};\r\n\r\nSender.prototype.deliverMessage = function() {\r\n\twhen(amqp.connect( this.addr_ ))\r\n\t\t.with( this )\r\n\t\t.then( this.createChannel_ )\r\n\t\t.then( this.createExchange_ )\r\n\t\t.then( this.handleUnrouteableMessages_ )\r\n\t\t.then( this.handleDisconnections_ )\r\n\t\t.catch( this.reconnect_ )\r\n\t\t.done( this.publish_ ); //? publish_ is invoked in all case?\r\n};\r\n```\r\n\r\nActually, whether the connection is succeeded or failed, `publish_` is called anyway. Could anyone help me to which API could I use in my case? "},"comment":{"url":"https://api.github.com/repos/cujojs/when/issues/comments/87888978","html_url":"https://github.com/cujojs/when/issues/426#issuecomment-87888978","issue_url":"https://api.github.com/repos/cujojs/when/issues/426","id":87888978,"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},"created_at":"2015-03-31T00:48:16Z","updated_at":"2015-03-31T00:48:16Z","body":"@briancavalier Got it, thanks "}}