Skip to content

Commit

Permalink
Make megaYield configurable by env var (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis authored Apr 27, 2023
1 parent a239970 commit 0625932
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/CombineSchedulers/TestScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,20 @@
> where Scheduler: Combine.Scheduler

extension Task where Success == Failure, Failure == Never {
static func megaYield(count: Int = 10) async {
for _ in 1...count {
// NB: We would love if this was not necessary. See this forum post for more information:
// https://forums.swift.org/t/reliably-testing-code-that-adopts-swift-concurrency/57304
static func megaYield(count: Int = defaultMegaYieldCount) async {
for _ in 0..<count {
await Task<Void, Never>.detached(priority: .background) { await Task.yield() }.value
}
}
}

let defaultMegaYieldCount = max(
0,
min(
ProcessInfo.processInfo.environment["TASK_MEGA_YIELD_COUNT"].flatMap(Int.init) ?? 20,
10_000
)
)
#endif

0 comments on commit 0625932

Please sign in to comment.