Skip to content

Instantly share code, notes, and snippets.

@alexdremov
Last active April 28, 2022 08:42
Show Gist options
  • Save alexdremov/bb414a29e0f57f14059cb68eb352fabb to your computer and use it in GitHub Desktop.
Save alexdremov/bb414a29e0f57f14059cb68eb352fabb to your computer and use it in GitHub Desktop.
Sequence 1 Sequence 2 Result
1 1
4 4
2 2
3 3
Sequence 1 Sequence 2 Result
1 awaits
2 (1, 2)
3 (1, 3)
4 (4, 3)
Sequence 1 Sequence 2 Result
awaits
1 1
2 2
3 3
4 4
extension AsyncSequence {
public func throttle<C: Clock, Reduced>(
for interval: C.Instant.Duration,
clock: C,
reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced
) -> AsyncThrottleSequence<Self, C, Reduced>
public func throttle<Reduced>(
for interval: Duration,
reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced
) -> AsyncThrottleSequence<Self, ContinuousClock, Reduced>
public func throttle<C: Clock>(
for interval: C.Instant.Duration,
clock: C,
latest: Bool = true
) -> AsyncThrottleSequence<Self, C, Element>
public func throttle(
for interval: Duration,
latest: Bool = true
) -> AsyncThrottleSequence<Self, ContinuousClock, Element>
}
Sequence 1 Sequence 2 Result
1 awaits
2 (1, 2)
3 awaits
4 (4, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment