TimerAsyncSequence
public final class TimerAsyncSequence : AsyncSequence
An async sequence that emits the current date on a given interval.
let sequence = TimerAsyncSequence(interval: 1)
let start = Date.now
for await element in sequence {
print(element)
}
// Prints:
// 2022-03-19 20:49:30 +0000
// 2022-03-19 20:49:31 +0000
// 2022-03-19 20:49:32 +0000
-
The kind of elements streamed.
Declaration
Swift
public typealias Element = Date
-
Creates an async sequence that emits the current date on a given interval.
Declaration
Swift
public init(interval: TimeInterval)
Parameters
interval
The interval on which to emit elements.
-
Cancel the sequence from emitting anymore elements.
Declaration
Swift
public func cancel()
-
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> PassthroughAsyncSequence<Element>.AsyncIterator
Return Value
An instance that conforms to
AsyncIteratorProtocol
.