Skip to content

Commit 3071180

Browse files
authored
Remove clock stubs and use the _Concurrency provided Clock APIs (apple#78)
* Remove the clock stubs * Add default implementations using clocks
1 parent 4b11faa commit 3071180

File tree

12 files changed

+26
-1151
lines changed

12 files changed

+26
-1151
lines changed

Package.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,34 @@ let package = Package(
1414
.library(
1515
name: "AsyncAlgorithms",
1616
targets: ["AsyncAlgorithms"]),
17-
.library(name: "ClockStub", type: .static, targets: ["ClockStub"]),
1817
.library(name: "AsyncSequenceValidation", targets: ["AsyncSequenceValidation"]),
1918
.library(name: "_CAsyncSequenceValidationSupport", type: .static, targets: ["AsyncSequenceValidation"])
2019
],
2120
dependencies: [],
2221
targets: [
2322
.target(
2423
name: "AsyncAlgorithms",
25-
dependencies: ["ClockStub"]),
26-
.target(name: "ClockStub"),
27-
.target(name: "AsyncSequenceValidation", dependencies: ["_CAsyncSequenceValidationSupport", "ClockStub"]),
24+
swiftSettings: [
25+
.unsafeFlags([
26+
"-Xfrontend", "-disable-availability-checking"
27+
])
28+
]),
29+
.target(
30+
name: "AsyncSequenceValidation",
31+
dependencies: ["_CAsyncSequenceValidationSupport"],
32+
swiftSettings: [
33+
.unsafeFlags([
34+
"-Xfrontend", "-disable-availability-checking"
35+
])
36+
]),
2837
.systemLibrary(name: "_CAsyncSequenceValidationSupport"),
2938
.testTarget(
3039
name: "AsyncAlgorithmsTests",
31-
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"]),
40+
dependencies: ["AsyncAlgorithms", "AsyncSequenceValidation"],
41+
swiftSettings: [
42+
.unsafeFlags([
43+
"-Xfrontend", "-disable-availability-checking"
44+
])
45+
]),
3246
]
3347
)

Sources/AsyncAlgorithms/AsyncDebounceSequence.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ extension AsyncSequence {
1313
public func debounce<C: Clock>(for interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncDebounceSequence<Self, C> {
1414
AsyncDebounceSequence(self, interval: interval, tolerance: tolerance, clock: clock)
1515
}
16+
17+
public func debounce(for interval: Duration, tolerance: Duration? = nil) -> AsyncDebounceSequence<Self, ContinuousClock> {
18+
debounce(for: interval, tolerance: tolerance, clock: .continuous)
19+
}
1620
}
1721

1822
public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable

Sources/AsyncAlgorithms/AsyncThrottleSequence.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ extension AsyncSequence {
1414
AsyncThrottleSequence(self, interval: interval, clock: clock, reducing: reducing)
1515
}
1616

17-
/*
1817
public func throttle<Reduced>(for interval: Duration, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence<Self, ContinuousClock, Reduced> {
1918
throttle(for: interval, clock: .continuous, reducing: reducing)
2019
}
21-
*/
2220

2321
public func throttle<C: Clock>(for interval: C.Instant.Duration, clock: C, latest: Bool = true) -> AsyncThrottleSequence<Self, C, Element> {
2422
throttle(for: interval, clock: clock) { previous, element in
@@ -30,11 +28,9 @@ extension AsyncSequence {
3028
}
3129
}
3230

33-
/*
3431
public func throttle(for interval: Duration, latest: Bool = true) -> AsyncThrottleSequence<Self, ContinuousClock, Element> {
3532
throttle(for: interval, clock: .continuous, latest: latest)
3633
}
37-
*/
3834
}
3935

4036
public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {

Sources/AsyncAlgorithms/AsyncTimerSequence.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ extension AsyncTimerSequence {
7373
}
7474
}
7575

76-
/*
76+
7777
extension AsyncTimerSequence where C == SuspendingClock {
7878
public static func repeating(every interval: Duration, tolerance: Duration? = nil) -> AsyncTimerSequence<SuspendingClock> {
7979
return AsyncTimerSequence(interval: interval, tolerance: tolerance, clock: SuspendingClock())
8080
}
8181
}
82-
*/
8382

8483
extension AsyncTimerSequence: Sendable { }
8584
extension AsyncTimerSequence.Iterator: Sendable { }

Sources/AsyncAlgorithms/Reexport.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sources/AsyncSequenceValidation/Clock.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
import ClockStub
13-
1412
extension AsyncSequenceValidationDiagram {
1513
public struct Clock {
1614
let queue: WorkQueue

Sources/AsyncSequenceValidation/Test.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import _CAsyncSequenceValidationSupport
13-
import ClockStub
1413

1514
@_silgen_name("swift_job_run")
1615
@usableFromInline
@@ -23,7 +22,7 @@ public protocol AsyncSequenceValidationTest: Sendable {
2322
var inputs: [String] { get }
2423
var output: String { get }
2524

26-
func test<C: ClockStub.Clock>(with clock: C, activeTicks: [C.Instant], _ event: (String) -> Void) async throws
25+
func test<C: Clock>(with clock: C, activeTicks: [C.Instant], _ event: (String) -> Void) async throws
2726
}
2827

2928
extension AsyncSequenceValidationDiagram {
@@ -32,7 +31,7 @@ extension AsyncSequenceValidationDiagram {
3231
let sequence: Operation
3332
let output: String
3433

35-
func test<C: ClockStub.Clock>(with clock: C, activeTicks: [C.Instant], _ event: (String) -> Void) async throws {
34+
func test<C: _Concurrency.Clock>(with clock: C, activeTicks: [C.Instant], _ event: (String) -> Void) async throws {
3635
var iterator = sequence.makeAsyncIterator()
3736
do {
3837
for tick in activeTicks {

Sources/ClockStub/Clock.swift

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)