diff --git a/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift b/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift index f515fe6a..4dbc1e48 100644 --- a/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift +++ b/Sources/AsyncAlgorithms/AsyncThrottleSequence.swift @@ -12,20 +12,20 @@ extension AsyncSequence { /// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) - public func throttle(for interval: C.Instant.Duration, clock: C, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence { - AsyncThrottleSequence(self, interval: interval, clock: clock, reducing: reducing) + public func _throttle(for interval: C.Instant.Duration, clock: C, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> _AsyncThrottleSequence { + _AsyncThrottleSequence(self, interval: interval, clock: clock, reducing: reducing) } /// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) - public func throttle(for interval: Duration, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence { - throttle(for: interval, clock: .continuous, reducing: reducing) + public func _throttle(for interval: Duration, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> _AsyncThrottleSequence { + _throttle(for: interval, clock: .continuous, reducing: reducing) } /// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) - public func throttle(for interval: C.Instant.Duration, clock: C, latest: Bool = true) -> AsyncThrottleSequence { - throttle(for: interval, clock: clock) { previous, element in + public func _throttle(for interval: C.Instant.Duration, clock: C, latest: Bool = true) -> _AsyncThrottleSequence { + _throttle(for: interval, clock: clock) { previous, element in if latest { return element } else { @@ -36,14 +36,14 @@ extension AsyncSequence { /// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) - public func throttle(for interval: Duration, latest: Bool = true) -> AsyncThrottleSequence { - throttle(for: interval, clock: .continuous, latest: latest) + public func _throttle(for interval: Duration, latest: Bool = true) -> _AsyncThrottleSequence { + _throttle(for: interval, clock: .continuous, latest: latest) } } /// A rate-limited `AsyncSequence` by emitting values at most every specified interval. @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) -public struct AsyncThrottleSequence { +public struct _AsyncThrottleSequence { let base: Base let interval: C.Instant.Duration let clock: C @@ -58,7 +58,7 @@ public struct AsyncThrottleSequence { } @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) -extension AsyncThrottleSequence: AsyncSequence { +extension _AsyncThrottleSequence: AsyncSequence { public typealias Element = Reduced /// The iterator for an `AsyncThrottleSequence` instance. @@ -110,7 +110,7 @@ extension AsyncThrottleSequence: AsyncSequence { } @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) -extension AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { } +extension _AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { } @available(*, unavailable) -extension AsyncThrottleSequence.Iterator: Sendable { } +extension _AsyncThrottleSequence.Iterator: Sendable { } diff --git a/Tests/AsyncAlgorithmsTests/TestThrottle.swift b/Tests/AsyncAlgorithmsTests/TestThrottle.swift index 4e0d3898..d7b60db3 100644 --- a/Tests/AsyncAlgorithmsTests/TestThrottle.swift +++ b/Tests/AsyncAlgorithmsTests/TestThrottle.swift @@ -17,7 +17,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(0), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(0), clock: $0.clock) "abcdefghijk|" } } @@ -26,7 +26,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(0), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(0), clock: $0.clock, latest: false) "abcdefghijk|" } } @@ -35,7 +35,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(1), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(1), clock: $0.clock) "abcdefghijk|" } } @@ -44,7 +44,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(1), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(1), clock: $0.clock, latest: false) "abcdefghijk|" } } @@ -53,7 +53,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock) "a-c-e-g-i-k|" } } @@ -62,7 +62,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock, latest: false) "a-b-d-f-h-j|" } } @@ -71,7 +71,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(3), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(3), clock: $0.clock) "a--d--g--j--[k|]" } } @@ -80,7 +80,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijk|" - $0.inputs[0].throttle(for: .steps(3), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(3), clock: $0.clock, latest: false) "a--b--e--h--[k|]" } } @@ -89,7 +89,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdef^hijk|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock) "a-c-e-^" } } @@ -98,7 +98,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdef^hijk|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock, latest: false) "a-b-d-^" } } @@ -107,7 +107,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "-a-b-c-d-e-f-g-h-i-j-k-|" - $0.inputs[0].throttle(for: .steps(1), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(1), clock: $0.clock) "-a-b-c-d-e-f-g-h-i-j-k-|" } } @@ -116,7 +116,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "-a-b-c-d-e-f-g-h-i-j-k-|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock) "-a-b-c-d-e-f-g-h-i-j-k-|" } } @@ -125,7 +125,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "--a--b--c--d--e--f--g|" - $0.inputs[0].throttle(for: .steps(2), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(2), clock: $0.clock) "--a--b--c--d--e--f--g|" } } @@ -134,7 +134,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "-a-b-c-d-e-f-g-h-i-j-k-|" - $0.inputs[0].throttle(for: .steps(3), clock: $0.clock) + $0.inputs[0]._throttle(for: .steps(3), clock: $0.clock) "-a---c---e---g---i---k-|" } } @@ -143,7 +143,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijkl|" - $0.inputs[0].throttle(for: .steps(3), clock: $0.clock, latest: false) + $0.inputs[0]._throttle(for: .steps(3), clock: $0.clock, latest: false) "a--b--e--h--[k|]" } } @@ -152,7 +152,7 @@ final class TestThrottle: XCTestCase { guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else { throw XCTSkip("Skipped due to Clock/Instant/Duration availability") } validate { "abcdefghijkl|" - $0.inputs[0].throttle(for: .steps(3), clock: $0.clock, latest: true) + $0.inputs[0]._throttle(for: .steps(3), clock: $0.clock, latest: true) "a--d--g--j--[l|]" } }