Skip to content

Instantly share code, notes, and snippets.

@foresta
Last active September 9, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foresta/1164682b8647ef977c5496293b557f41 to your computer and use it in GitHub Desktop.
Save foresta/1164682b8647ef977c5496293b557f41 to your computer and use it in GitHub Desktop.
Async Request Sample
func getFriends() {
let numberOfParallel: Int = 2
var completionCount: Int = 0
// 呼ばれるたびに 1ずつ足していって並列実行数を超えたら何かのメソッドを呼ぶ
completion = []() {
completionCount += 1
if (numberOfParallel >= comletionCount) {
// 突合する処理など
doSomethingAfterFetchFriends()
}
}
// メソッドの内部で終了時に、completionコールバックを呼ぶ
getFollows(completion: completion)
getFollowers(completion: completion)
}
private func getFollows(completion: @escaping () -> Void) {
doAsyncSomething() {
completion()
}
}
private func getFollowers(completion: @escaping () -> Void) {
doAsyncSomething() {
completion()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment