Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement