Skip to content

Commit

Permalink
Merge pull request #48 from freshOS/fix-whenall
Browse files Browse the repository at this point in the history
Fix when all concurrency.
  • Loading branch information
s4cha authored Sep 19, 2018
2 parents e659cad + 70443b3 commit 024cc46
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions Source/WhenAll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension Promises {
for p in promises {
group.enter()
p.then { element in
updatePartialResult(&ts.array, element)
ts.updateArray({ updatePartialResult(&$0, element) })
}
.onError { error = $0 }
.finally { group.leave() }
Expand All @@ -121,16 +121,15 @@ extension Promises {
private var _array: [T] = []
private let lockQueue = DispatchQueue(label: "com.freshOS.then.whenAll.lockQueue", qos: .userInitiated)

var array: [T] {
get {
return lockQueue.sync {
_array
}
func updateArray(_ updates: @escaping (_ result: inout [T]) -> Void) {
lockQueue.async {
updates(&self._array)
}
set {
lockQueue.sync {
_array = newValue
}
}

var array: [T] {
return lockQueue.sync {
_array
}
}
}
Expand Down

0 comments on commit 024cc46

Please sign in to comment.