{"action":"created","issue":{"url":"https://api.github.com/repos/mxcl/PromiseKit/issues/469","repository_url":"https://api.github.com/repos/mxcl/PromiseKit","labels_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/469/labels{/name}","comments_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/469/comments","events_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/469/events","html_url":"https://github.com/mxcl/PromiseKit/issues/469","id":164781139,"number":469,"title":"Newbie question","user":{"login":"kwstasna","id":13165044,"avatar_url":"https://avatars.githubusercontent.com/u/13165044?v=3","gravatar_id":"","url":"https://api.github.com/users/kwstasna","html_url":"https://github.com/kwstasna","followers_url":"https://api.github.com/users/kwstasna/followers","following_url":"https://api.github.com/users/kwstasna/following{/other_user}","gists_url":"https://api.github.com/users/kwstasna/gists{/gist_id}","starred_url":"https://api.github.com/users/kwstasna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kwstasna/subscriptions","organizations_url":"https://api.github.com/users/kwstasna/orgs","repos_url":"https://api.github.com/users/kwstasna/repos","events_url":"https://api.github.com/users/kwstasna/events{/privacy}","received_events_url":"https://api.github.com/users/kwstasna/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-07-11T08:06:54Z","updated_at":"2016-07-11T16:05:23Z","closed_at":null,"body":"Hello guys. Thanks for your great library here!!\r\n\r\nWanted to ask you a newbie question. I'm now starting learning swift and of course i'm a bit confused with asynchronous functions. I'm using Parse to get and to save data.\r\nSo i have 2 functions.\r\n\r\n```\r\nfunc one() {\r\nbrings all the likes of the user and save them into an array\r\n}\r\n\r\nfunc two() {\r\nbrings all the posts and append them to a cell\r\n}\r\n```\r\n\r\nI would like you to give me an example of your promises how to make `func two()` to run ALWAYS when `func one()` finishes.\r\n\r\nI was thingking about calling `func two()` within the success closure of the `func one()` but its not that good coding quality.\r\n\r\nThanks a lot for your time and sorry if this is a newbish question at all. Trying to learn quality stuff!"},"comment":{"url":"https://api.github.com/repos/mxcl/PromiseKit/issues/comments/231781196","html_url":"https://github.com/mxcl/PromiseKit/issues/469#issuecomment-231781196","issue_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/469","id":231781196,"user":{"login":"nathanhosselton","id":7957896,"avatar_url":"https://avatars.githubusercontent.com/u/7957896?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanhosselton","html_url":"https://github.com/nathanhosselton","followers_url":"https://api.github.com/users/nathanhosselton/followers","following_url":"https://api.github.com/users/nathanhosselton/following{/other_user}","gists_url":"https://api.github.com/users/nathanhosselton/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanhosselton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanhosselton/subscriptions","organizations_url":"https://api.github.com/users/nathanhosselton/orgs","repos_url":"https://api.github.com/users/nathanhosselton/repos","events_url":"https://api.github.com/users/nathanhosselton/events{/privacy}","received_events_url":"https://api.github.com/users/nathanhosselton/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T16:05:23Z","updated_at":"2016-07-11T16:05:23Z","body":"Probably http://promisekit.org/sealing-your-own-promises/ is a good place to start. It even has examples that use Parse.\r\n\r\nAlso, building off the prior example, if you only want `two()` to run when `one()` is _successful_ (which is the common pattern), you would use `then` instead of `always` and act on failure of either within `error`:\r\n```swift\r\none().then { (likes) -> Promise<[Post]> in\r\n    // handle likes\r\n    return two()\r\n}.then { (posts) in\r\n    // handle posts\r\n}.error { (error:ErrorType) in\r\n    // Display a message to the user, etc\r\n}\r\n```\r\nAgain, presuming that `one()` and `two()` both return Promises.\r\n\r\nNote that `error` ends the promise chain. If you wish to handle an error and continue the promise chain you would use `recover` before `error`."}}
{"actor":{"display_login":"nathanhosselton"}}