diff --git a/Package.swift b/Package.swift index 2768b01e6..ad17e8b62 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( ], dependencies: [ .package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"), - .package(url: "https://github.com/ReactiveCocoa/ReactiveSwift", from: "6.7.0"), + .package(url: "https://github.com/ReactiveCocoa/ReactiveSwift", branch: "7.1.0"), .package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.8.0"), .package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.3.0"), .package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "0.3.2"), diff --git a/Sources/ComposableArchitecture/SchedulerExtensions/SchedulerExtensions.swift b/Sources/ComposableArchitecture/SchedulerExtensions/SchedulerExtensions.swift index 15d64a2e0..bb89c6340 100644 --- a/Sources/ComposableArchitecture/SchedulerExtensions/SchedulerExtensions.swift +++ b/Sources/ComposableArchitecture/SchedulerExtensions/SchedulerExtensions.swift @@ -47,121 +47,3 @@ } } #endif - -#if canImport(_Concurrency) && compiler(>=5.5.2) - import Foundation - import ReactiveSwift - - @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, *) - extension DateScheduler { - - /// Suspends the current task for at least the given duration. - /// - /// If the task is cancelled before the time ends, this function throws `CancellationError`. - /// - /// This function doesn't block the scheduler. - /// - /// ``` - /// try await in scheduler.sleep(for: .seconds(1)) - /// ``` - /// - /// - Parameters: - /// - duration: The time interval on which to sleep between yielding. - /// - leeway: The allowed timing variance when emitting events. Defaults to `.seconds(0)`. - public func sleep( - for interval: DispatchTimeInterval, - leeway: DispatchTimeInterval = .seconds(0) - ) async throws { - try Task.checkCancellation() - _ = await self.timer(interval: interval, leeway: leeway) - .first { _ in true } - try Task.checkCancellation() - } - - /// Suspend task execution until a given deadline within a tolerance. - /// - /// If the task is cancelled before the time ends, this function throws `CancellationError`. - /// - /// This function doesn't block the scheduler. - /// - /// ``` - /// try await in scheduler.sleep(until: scheduler.now + .seconds(1)) - /// ``` - /// - Parameters: - /// - deadline: An instant of time to suspend until. - /// - leeway: The allowed timing variance when emitting events. Defaults to `.seconds(0)`. - public func sleep( - until deadline: Date, - leeway: DispatchTimeInterval = .seconds(0) - ) async throws { - precondition(deadline > currentDate) - try await self.sleep( - for: deadline.timeIntervalSince(currentDate).dispatchTimeInterval, - leeway: leeway - ) - } - - /// Returns a stream that repeatedly yields the current time of the scheduler on a given interval. - /// - /// If the task is cancelled, the sequence will terminate. - /// - /// ``` - /// for await instant in scheduler.timer(interval: .seconds(1)) { - /// print("now:", instant) - /// } - /// ``` - /// - /// - Parameters: - /// - interval: The time interval on which to sleep between yielding the current instant in - /// time. For example, a value of `0.5` yields an instant approximately every half-second. - /// - leeway: The allowed timing variance when emitting events. Defaults to `.seconds(0)`. - /// - Returns: A stream that repeatedly yields the current time. - public func timer( - interval: DispatchTimeInterval, - leeway: DispatchTimeInterval = .seconds(0) - ) -> AsyncStream { - .init { continuation in - let disposable = self.schedule( - after: currentDate.addingTimeInterval(interval.timeInterval), - interval: interval, - leeway: leeway - ) { - continuation.yield(self.currentDate) - } - continuation.onTermination = - { _ in - disposable?.dispose() - } - // NB: This explicit cast is needed to work around a compiler bug in Swift 5.5.2 - as @Sendable (AsyncStream.Continuation.Termination) -> Void - } - } - } - - extension DispatchTimeInterval { - - var timeInterval: TimeInterval { - switch self { - case let .seconds(s): - return TimeInterval(s) - case let .milliseconds(ms): - return TimeInterval(TimeInterval(ms) / 1000.0) - case let .microseconds(us): - return TimeInterval(Int64(us)) * TimeInterval(NSEC_PER_USEC) / TimeInterval(NSEC_PER_SEC) - case let .nanoseconds(ns): - return TimeInterval(ns) / TimeInterval(NSEC_PER_SEC) - case .never: - return .infinity - @unknown default: - return .infinity - } - } - } - - extension TimeInterval { - - var dispatchTimeInterval: DispatchTimeInterval { - .nanoseconds(Int(self * TimeInterval(NSEC_PER_SEC))) - } - } -#endif diff --git a/Tests/ComposableArchitectureTests/TestStoreTests.swift b/Tests/ComposableArchitectureTests/TestStoreTests.swift index 15384574c..37a85c83e 100644 --- a/Tests/ComposableArchitectureTests/TestStoreTests.swift +++ b/Tests/ComposableArchitectureTests/TestStoreTests.swift @@ -11,8 +11,6 @@ class TestStoreTests: XCTestCase { case a, b1, b2, b3, c1, c2, c3, d } - let testScheduler = TestScheduler() - let reducer = Reducer { _, action, scheduler in switch action { case .a: