Skip to content

Commit

Permalink
Realized that the real underlying problem with the Future.merge(_:) w…
Browse files Browse the repository at this point in the history
…as a deadlock because the zipping and resolving were happening from the same thread and blocking one another.
  • Loading branch information
jakehawken committed Jul 11, 2022
1 parent fabad71 commit 9d2c1a3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Sources/Propagate/PromiseAndFuture/Future+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ public extension Future {
- returns: A future where the success value is an array of the success values from the array of promises, and the error
is whichever error happened first.
*/
static func merge(_ futures: [Future<T, E>]) -> Future<[T], E> {
let promise = Promise<[T], E>()
static func merge(_ futures: [Future<T,E>]) -> Future<[T],E> {
let promise = Promise<[T],E>()
let queue = DispatchQueue(label: "\(Future<T,E>.self) Merge Queue")

futures.forEach { future in
future.finally { (_) in
promise.future.lockQueue.async {
queue.async {
guard promise.future.isComplete == false else {
return
}
Expand Down

0 comments on commit 9d2c1a3

Please sign in to comment.