From 6d98d5743995ddf2f6b7e05feb95240e16146c57 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 14 Jun 2024 14:05:28 -0700 Subject: [PATCH] wip --- Sources/ConcurrencyExtras/AsyncStream.swift | 60 ------------------ .../AsyncThrowingStream.swift | 62 ------------------- 2 files changed, 122 deletions(-) diff --git a/Sources/ConcurrencyExtras/AsyncStream.swift b/Sources/ConcurrencyExtras/AsyncStream.swift index 6dfa2ea..d547647 100644 --- a/Sources/ConcurrencyExtras/AsyncStream.swift +++ b/Sources/ConcurrencyExtras/AsyncStream.swift @@ -65,66 +65,6 @@ extension AsyncStream { } } - #if swift(<5.9) - /// Constructs and returns a stream along with its backing continuation. - /// - /// A back-port of [SE-0388: Convenience Async[Throwing]Stream.makeStream methods][se-0388]. - /// - /// This is handy for immediately escaping the continuation from an async stream, which - /// typically requires multiple steps: - /// - /// ```swift - /// var _continuation: AsyncStream.Continuation! - /// let stream = AsyncStream { continuation = $0 } - /// let continuation = _continuation! - /// - /// // vs. - /// - /// let (stream, continuation) = AsyncStream.makeStream(of: Int.self) - /// ``` - /// - /// This tool is usually used for tests where we need to supply an async sequence to a - /// dependency endpoint and get access to its continuation so that we can emulate the dependency - /// emitting data. For example, suppose you have a dependency exposing an async sequence for - /// listening to notifications. To test this you can use `makeStream`: - /// - /// ```swift - /// func testScreenshots() { - /// let screenshots = AsyncStream.makeStream(of: Void.self) - /// - /// let model = withDependencies { - /// $0.screenshots = { screenshots.stream } - /// } operation: { - /// FeatureModel() - /// } - /// - /// XCTAssertEqual(model.screenshotCount, 0) - /// screenshots.continuation.yield() // Simulate a screenshot being taken. - /// XCTAssertEqual(model.screenshotCount, 1) - /// } - /// ``` - /// - /// > Warning: ⚠️ `AsyncStream` does not support multiple subscribers, therefore you can only - /// > use this helper to test features that do not subscribe multiple times to the dependency - /// > endpoint. - /// - /// [se-0388]: https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md - /// - /// - Parameters: - /// - elementType: The type of element the `AsyncStream` produces. - /// - limit: A Continuation.BufferingPolicy value to set the stream’s buffering behavior. By - /// default, the stream buffers an unlimited number of elements. You can also set the policy - /// to buffer a specified number of oldest or newest elements. - /// - Returns: An `AsyncStream`. - public static func makeStream( - of elementType: Element.Type = Element.self, - bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded - ) -> (stream: Self, continuation: Continuation) { - var continuation: Continuation! - return (Self(elementType, bufferingPolicy: limit) { continuation = $0 }, continuation) - } - #endif - /// An `AsyncStream` that never emits and never completes unless cancelled. public static var never: Self { Self { _ in } diff --git a/Sources/ConcurrencyExtras/AsyncThrowingStream.swift b/Sources/ConcurrencyExtras/AsyncThrowingStream.swift index 829b0ae..cb16e23 100644 --- a/Sources/ConcurrencyExtras/AsyncThrowingStream.swift +++ b/Sources/ConcurrencyExtras/AsyncThrowingStream.swift @@ -18,68 +18,6 @@ extension AsyncThrowingStream where Failure == Error { } } - #if swift(<5.9) - /// Constructs and returns a stream along with its backing continuation. - /// - /// A back-port of [SE-0388: Convenience Async[Throwing]Stream.makeStream methods][se-0388]. - /// - /// This is handy for immediately escaping the continuation from an async stream, which - /// typically requires multiple steps: - /// - /// ```swift - /// var _continuation: AsyncThrowingStream.Continuation! - /// let stream = AsyncThrowingStream { continuation = $0 } - /// let continuation = _continuation! - /// - /// // vs. - /// - /// let (stream, continuation) = AsyncThrowingStream.makeStream(of: Int.self) - /// ``` - /// - /// This tool is usually used for tests where we need to supply an async sequence to a - /// dependency endpoint and get access to its continuation so that we can emulate the dependency - /// emitting data. For example, suppose you have a dependency exposing an async sequence for - /// listening to notifications. To test this you can use `makeStream`: - /// - /// ```swift - /// func testScreenshots() { - /// let screenshots = AsyncThrowingStream.makeStream(of: Void.self) - /// - /// let model = withDependencies { - /// $0.screenshots = { screenshots.stream } - /// } operation: { - /// FeatureModel() - /// } - /// - /// XCTAssertEqual(model.screenshotCount, 0) - /// screenshots.continuation.yield() // Simulate a screenshot being taken. - /// XCTAssertEqual(model.screenshotCount, 1) - /// } - /// ``` - /// - /// > Warning: ⚠️ `AsyncThrowingStream` does not support multiple subscribers, therefore you can - /// > only use this helper to test features that do not subscribe multiple times to the - /// > dependency endpoint. - /// - /// [se-0388]: https://github.com/apple/swift-evolution/blob/main/proposals/0388-async-stream-factory.md - /// - /// - Parameters: - /// - elementType: The type of element the `AsyncThrowingStream` produces. - /// - failureType: The type of failure the `AsyncThrowingStream` throws. - /// - limit: A Continuation.BufferingPolicy value to set the stream’s buffering behavior. By - /// default, the stream buffers an unlimited number of elements. You can also set the policy - /// to buffer a specified number of oldest or newest elements. - /// - Returns: An `AsyncThrowingStream`. - public static func makeStream( - of elementType: Element.Type = Element.self, - throwing failureType: Failure.Type = Failure.self, - bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded - ) -> (stream: Self, continuation: Continuation) { - var continuation: Continuation! - return (Self(elementType, bufferingPolicy: limit) { continuation = $0 }, continuation) - } - #endif - /// An `AsyncThrowingStream` that never emits and never completes unless cancelled. public static var never: Self { Self { _ in }