Skip to content

Commit

Permalink
Depend on ConcurrencyExtras (#88)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip
  • Loading branch information
stephencelis authored Jul 17, 2023
1 parent 93186c0 commit ec62f32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "swift-concurrency-extras",
"repositoryURL": "https://github.com/pointfreeco/swift-concurrency-extras",
"state": {
"branch": null,
"revision": "ecb065a41bbdd7f64ab2695ffc755ed37c9ff4dc",
"version": "0.1.0"
}
},
{
"package": "xctest-dynamic-overlay",
"repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay",
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.8.5")
],
targets: [
.target(
name: "CombineSchedulers",
dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
Expand Down
19 changes: 1 addition & 18 deletions Sources/CombineSchedulers/TestScheduler.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(Combine)
import Combine
import ConcurrencyExtras
import Foundation

/// A scheduler whose current time and execution can be controlled in a deterministic manner.
Expand Down Expand Up @@ -283,22 +284,4 @@
public typealias TestSchedulerOf<Scheduler> = TestScheduler<
Scheduler.SchedulerTimeType, Scheduler.SchedulerOptions
> where Scheduler: Combine.Scheduler

extension Task where Success == Failure, Failure == Never {
// 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 ec62f32

Please sign in to comment.