mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-30 04:58:44 +00:00
Restore availability and mark everything as 9999 to match stdlib availability for 5.7 for now (#82)
This commit is contained in:
1 parent
ed1d2a04cf
commit
822ca9365c
15 files changed
+39
-8
No files matched your search
@@ -26,18 +26,22 @@ extension AsyncSequence {
|
||||
chunked(by: signal, into: [Element].self)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func chunks<C: Clock, Collected: RangeReplaceableCollection>(ofCount count: Int, or timer: AsyncTimerSequence<C>, into: Collected.Type) -> AsyncChunksOfCountOrSignalSequence<Self, Collected, AsyncTimerSequence<C>> where Collected.Element == Element {
|
||||
AsyncChunksOfCountOrSignalSequence(self, count: count, signal: timer)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func chunks<C: Clock>(ofCount count: Int, or timer: AsyncTimerSequence<C>) -> AsyncChunksOfCountOrSignalSequence<Self, [Element], AsyncTimerSequence<C>> {
|
||||
chunks(ofCount: count, or: timer, into: [Element].self)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func chunked<C: Clock, Collected: RangeReplaceableCollection>(by timer: AsyncTimerSequence<C>, into: Collected.Type) -> AsyncChunksOfCountOrSignalSequence<Self, Collected, AsyncTimerSequence<C>> where Collected.Element == Element {
|
||||
AsyncChunksOfCountOrSignalSequence(self, count: nil, signal: timer)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func chunked<C: Clock>(by timer: AsyncTimerSequence<C>) -> AsyncChunksOfCountOrSignalSequence<Self, [Element], AsyncTimerSequence<C>> {
|
||||
chunked(by: timer, into: [Element].self)
|
||||
}
|
||||
|
||||
@@ -10,15 +10,18 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension AsyncSequence {
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func debounce<C: Clock>(for interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncDebounceSequence<Self, C> {
|
||||
AsyncDebounceSequence(self, interval: interval, tolerance: tolerance, clock: clock)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func debounce(for interval: Duration, tolerance: Duration? = nil) -> AsyncDebounceSequence<Self, ContinuousClock> {
|
||||
debounce(for: interval, tolerance: tolerance, clock: .continuous)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable
|
||||
where Base.AsyncIterator: Sendable, Base.Element: Sendable, Base: Sendable {
|
||||
let base: Base
|
||||
@@ -34,6 +37,7 @@ public struct AsyncDebounceSequence<Base: AsyncSequence, C: Clock>: Sendable
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncDebounceSequence: AsyncSequence {
|
||||
public typealias Element = Base.Element
|
||||
|
||||
|
||||
@@ -10,14 +10,17 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
extension AsyncSequence {
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func throttle<C: Clock, Reduced>(for interval: C.Instant.Duration, clock: C, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence<Self, C, Reduced> {
|
||||
AsyncThrottleSequence(self, interval: interval, clock: clock, reducing: reducing)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func throttle<Reduced>(for interval: Duration, reducing: @Sendable @escaping (Reduced?, Element) async -> Reduced) -> AsyncThrottleSequence<Self, ContinuousClock, Reduced> {
|
||||
throttle(for: interval, clock: .continuous, reducing: reducing)
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func throttle<C: Clock>(for interval: C.Instant.Duration, clock: C, latest: Bool = true) -> AsyncThrottleSequence<Self, C, Element> {
|
||||
throttle(for: interval, clock: clock) { previous, element in
|
||||
if latest {
|
||||
@@ -28,11 +31,13 @@ extension AsyncSequence {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public func throttle(for interval: Duration, latest: Bool = true) -> AsyncThrottleSequence<Self, ContinuousClock, Element> {
|
||||
throttle(for: interval, clock: .continuous, latest: latest)
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {
|
||||
let base: Base
|
||||
let interval: C.Instant.Duration
|
||||
@@ -47,6 +52,7 @@ public struct AsyncThrottleSequence<Base: AsyncSequence, C: Clock, Reduced> {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncThrottleSequence: AsyncSequence {
|
||||
public typealias Element = Reduced
|
||||
|
||||
@@ -85,5 +91,8 @@ extension AsyncThrottleSequence: AsyncSequence {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncThrottleSequence: Sendable where Base: Sendable, Element: Sendable { }
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncThrottleSequence.Iterator: Sendable where Base.AsyncIterator: Sendable { }
|
||||
@@ -9,6 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
public struct AsyncTimerSequence<C: Clock>: AsyncSequence {
|
||||
public typealias Element = C.Instant
|
||||
|
||||
@@ -67,18 +68,22 @@ public struct AsyncTimerSequence<C: Clock>: AsyncSequence {
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncTimerSequence {
|
||||
public static func repeating(every interval: C.Instant.Duration, tolerance: C.Instant.Duration? = nil, clock: C) -> AsyncTimerSequence<C> {
|
||||
return AsyncTimerSequence(interval: interval, tolerance: tolerance, clock: clock)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncTimerSequence where C == SuspendingClock {
|
||||
public static func repeating(every interval: Duration, tolerance: Duration? = nil) -> AsyncTimerSequence<SuspendingClock> {
|
||||
return AsyncTimerSequence(interval: interval, tolerance: tolerance, clock: SuspendingClock())
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncTimerSequence: Sendable { }
|
||||
|
||||
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *)
|
||||
extension AsyncTimerSequence.Iterator: Sendable { }
|
||||
Reference in new issue
Block a user