Empty

public struct Empty<Element> : AsyncSequence
extension Empty: AsyncIteratorProtocol

An asynchronous sequence that only emits the provided value once.

Empty<Int>().sink(
    receiveValue: { print($0) },
    receiveCompletion: { completion in
        switch completion {
        case .finished:
            print("Finished")
        case .failure:
            print("Failed")
        }
    }
)

// Prints:
// Finished

Initialization

  • Creates an empty async sequence.

    Declaration

    Swift

    public init(completeImmediately: Bool = true)

    Parameters

    completeImmediately

    A Boolean value that indicates whether the async sequence should immediately finish.

AsyncSequence

  • Creates an async iterator that emits elements of this async sequence.

    Declaration

    Swift

    public func makeAsyncIterator() -> Empty<Element>

    Return Value

    An instance that conforms to AsyncIteratorProtocol.

AsyncIteratorProtocol

  • next() Asynchronous

    Produces the next element in the sequence.

    Because this is an empty sequence, this will always be nil.

    Declaration

    Swift

    public mutating func next() async -> Element?

    Return Value

    nil as this is an empty sequence.