{"action":"created","issue":{"url":"https://api.github.com/repos/mxcl/PromiseKit/issues/512","repository_url":"https://api.github.com/repos/mxcl/PromiseKit","labels_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/512/labels{/name}","comments_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/512/comments","events_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/512/events","html_url":"https://github.com/mxcl/PromiseKit/issues/512","id":172125574,"number":512,"title":"How do you use this lib to execute a function after a for loop is complete","user":{"login":"simonnarang","id":9156815,"avatar_url":"https://avatars.githubusercontent.com/u/9156815?v=3","gravatar_id":"","url":"https://api.github.com/users/simonnarang","html_url":"https://github.com/simonnarang","followers_url":"https://api.github.com/users/simonnarang/followers","following_url":"https://api.github.com/users/simonnarang/following{/other_user}","gists_url":"https://api.github.com/users/simonnarang/gists{/gist_id}","starred_url":"https://api.github.com/users/simonnarang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonnarang/subscriptions","organizations_url":"https://api.github.com/users/simonnarang/orgs","repos_url":"https://api.github.com/users/simonnarang/repos","events_url":"https://api.github.com/users/simonnarang/events{/privacy}","received_events_url":"https://api.github.com/users/simonnarang/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-19T12:56:41Z","updated_at":"2016-08-22T19:28:28Z","closed_at":"2016-08-21T16:43:04Z","body":"How do you use this lib to execute a function after a for loop that is within a promise is complete\r\nfor example, in the following code i want to fulfill after the for loop completes:\r\n```swift\r\nfunc getItems(restaurantGuid: String, authToken: String, itemGuids: [String]) -> Promise<[MenuItem]> {\r\n        \r\n        return Promise { fulfill, reject in\r\n            \r\n            for itemGuid in itemGuids {\r\n            \r\n                Alamofire.request(\r\n                .GET,\r\n                \"https://ws-sandbox.eng.toasttab.com/config/v1/menuItems/\\(itemGuid)\",\r\n                parameters: [:],\r\n                encoding: .url,\r\n                headers: [\"Authorization\" : authToken, \"Toast-Restaurant-External-ID\" : restaurantGuid]\r\n                ).validate().responseJSON { (response) -> Void in\r\n                        \r\n                    switch response.result {\r\n                    case .success:\r\n                        let itemJson = JSON(response.result.value!)\r\n                        if let itemName = itemJson[\"name\"].string {\r\n                            self.loadingItems.append(MenuItem(name: itemName, price: \"$52.00\", isCart: false))\r\n                        }  \r\n                        break\r\n                    case .failure(let error):\r\n                        print(\"💩 menuItems request to the Toast API failed with the following error: \\(error), this was the item's guid: \\(itemGuid)\")\r\n                        break\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/mxcl/PromiseKit/issues/comments/241522790","html_url":"https://github.com/mxcl/PromiseKit/issues/512#issuecomment-241522790","issue_url":"https://api.github.com/repos/mxcl/PromiseKit/issues/512","id":241522790,"user":{"login":"mxcl","id":58962,"avatar_url":"https://avatars.githubusercontent.com/u/58962?v=3","gravatar_id":"","url":"https://api.github.com/users/mxcl","html_url":"https://github.com/mxcl","followers_url":"https://api.github.com/users/mxcl/followers","following_url":"https://api.github.com/users/mxcl/following{/other_user}","gists_url":"https://api.github.com/users/mxcl/gists{/gist_id}","starred_url":"https://api.github.com/users/mxcl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxcl/subscriptions","organizations_url":"https://api.github.com/users/mxcl/orgs","repos_url":"https://api.github.com/users/mxcl/repos","events_url":"https://api.github.com/users/mxcl/events{/privacy}","received_events_url":"https://api.github.com/users/mxcl/received_events","type":"User","site_admin":false},"created_at":"2016-08-22T19:28:28Z","updated_at":"2016-08-22T19:28:28Z","body":"np, I don't expect responses, but I do keep my issues track clean as much as possible."}}
{"actor":{"display_login":"mxcl"}}