Skip to content

Commit

Permalink
Make barrierQueue serial to resolve vadymmarkov#26
Browse files Browse the repository at this point in the history
  • Loading branch information
Montak Oleg committed Jan 22, 2018
1 parent 8060f6b commit ecf382c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/When/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

let backgroundQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.background)
let instantQueue = DispatchQueue(label: "When.InstantQueue", attributes: [])
let barrierQueue = DispatchQueue(label: "When.BarrierQueue", attributes: DispatchQueue.Attributes.concurrent)
let barrierQueue = DispatchQueue(label: "When.BarrierQueue", attributes: [])

public func when<T, U>(_ p1: Promise<T>, _ p2: Promise<U>) -> Promise<(T, U)> {
return when([p1.asVoid(on: instantQueue), p2.asVoid(on: instantQueue)]).then(on: instantQueue) { _ in
Expand Down
23 changes: 23 additions & 0 deletions WhenTests/Shared/FunctionsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ class FunctionsSpec: QuickSpec {
self.waitForExpectations(timeout: 2.0, handler:nil)
}
}

context("with many concurrent tasks") {
it("resolves the promise") {
let promises: [Promise<Int>] = (0..<10000).map { _ in
let promise = Promise<Int>(queue: DispatchQueue.global(), { resolve in
// +1 needed to avoid https://github.com/vadymmarkov/When/issues/27
DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + 1) {
resolve(1)
}
})
return promise
}

let doneExpectation = self.expectation(description: "Done expectation")

when(promises)
.done({ result in
doneExpectation.fulfill()
})

self.waitForExpectations(timeout: 2.0, handler:nil)
}
}
}
}
}
Expand Down

0 comments on commit ecf382c

Please # to comment.