Just
public struct Just<Element> : AsyncSequence
extension Just: AsyncIteratorProtocol
An asynchronous sequence that only emits the provided value once.
let stream = Just(1)
for await value in stream {
print(value)
}
// Prints:
// 1
-
Creates an async sequence that emits an element once.
Declaration
Swift
public init(_ element: Element)
Parameters
element
The element to emit.
-
next()
AsynchronousProduces the next element in the sequence.
Declaration
Swift
public mutating func next() async -> Element?
Return Value
The next element or
nil
if the end of the sequence is reached. -
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> Just<Element>
Return Value
An instance that conforms to
AsyncIteratorProtocol
.