12
12
extension AsyncSequence {
13
13
/// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval.
14
14
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
15
- public func throttle< C: Clock , Reduced> ( for interval: C . Instant . Duration , clock: C , reducing: @Sendable @escaping ( Reduced? , Element) async -> Reduced ) -> AsyncThrottleSequence < Self , C , Reduced > {
15
+ func throttle< C: Clock , Reduced> ( for interval: C . Instant . Duration , clock: C , reducing: @Sendable @escaping ( Reduced? , Element) async -> Reduced ) -> AsyncThrottleSequence < Self , C , Reduced > {
16
16
AsyncThrottleSequence ( self , interval: interval, clock: clock, reducing: reducing)
17
17
}
18
18
19
19
/// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval.
20
20
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
21
- public func throttle< Reduced> ( for interval: Duration , reducing: @Sendable @escaping ( Reduced? , Element) async -> Reduced ) -> AsyncThrottleSequence < Self , ContinuousClock , Reduced > {
21
+ func throttle< Reduced> ( for interval: Duration , reducing: @Sendable @escaping ( Reduced? , Element) async -> Reduced ) -> AsyncThrottleSequence < Self , ContinuousClock , Reduced > {
22
22
throttle ( for: interval, clock: . continuous, reducing: reducing)
23
23
}
24
24
25
25
/// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval.
26
26
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
27
- public func throttle< C: Clock > ( for interval: C . Instant . Duration , clock: C , latest: Bool = true ) -> AsyncThrottleSequence < Self , C , Element > {
27
+ func throttle< C: Clock > ( for interval: C . Instant . Duration , clock: C , latest: Bool = true ) -> AsyncThrottleSequence < Self , C , Element > {
28
28
throttle ( for: interval, clock: clock) { previous, element in
29
29
if latest {
30
30
return element
@@ -36,14 +36,14 @@ extension AsyncSequence {
36
36
37
37
/// Create a rate-limited `AsyncSequence` by emitting values at most every specified interval.
38
38
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
39
- public func throttle( for interval: Duration , latest: Bool = true ) -> AsyncThrottleSequence < Self , ContinuousClock , Element > {
39
+ func throttle( for interval: Duration , latest: Bool = true ) -> AsyncThrottleSequence < Self , ContinuousClock , Element > {
40
40
throttle ( for: interval, clock: . continuous, latest: latest)
41
41
}
42
42
}
43
43
44
44
/// A rate-limited `AsyncSequence` by emitting values at most every specified interval.
45
45
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
46
- public struct AsyncThrottleSequence < Base: AsyncSequence , C: Clock , Reduced> {
46
+ struct AsyncThrottleSequence < Base: AsyncSequence , C: Clock , Reduced> {
47
47
let base : Base
48
48
let interval : C . Instant . Duration
49
49
let clock : C
@@ -59,10 +59,10 @@ public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {
59
59
60
60
@available ( macOS 13 . 0 , iOS 16 . 0 , watchOS 9 . 0 , tvOS 16 . 0 , * )
61
61
extension AsyncThrottleSequence : AsyncSequence {
62
- public typealias Element = Reduced
62
+ typealias Element = Reduced
63
63
64
64
/// The iterator for an `AsyncThrottleSequence` instance.
65
- public struct Iterator : AsyncIteratorProtocol {
65
+ struct Iterator : AsyncIteratorProtocol {
66
66
var base : Base . AsyncIterator
67
67
var last : C . Instant ?
68
68
let interval : C . Instant . Duration
@@ -76,7 +76,7 @@ extension AsyncThrottleSequence: AsyncSequence {
76
76
self . reducing = reducing
77
77
}
78
78
79
- public mutating func next( ) async rethrows -> Reduced ? {
79
+ mutating func next( ) async rethrows -> Reduced ? {
80
80
var reduced : Reduced ?
81
81
let start = last ?? clock. now
82
82
repeat {
@@ -95,7 +95,7 @@ extension AsyncThrottleSequence: AsyncSequence {
95
95
}
96
96
}
97
97
98
- public func makeAsyncIterator( ) -> Iterator {
98
+ func makeAsyncIterator( ) -> Iterator {
99
99
Iterator ( base. makeAsyncIterator ( ) , interval: interval, clock: clock, reducing: reducing)
100
100
}
101
101
}
0 commit comments