CurrentElementAsyncSequence

public actor CurrentElementAsyncSequence<Element> : AsyncSequence

A async sequence that wraps a single value and emits a new element whenever the element changes.

let sequence = CurrentElementAsyncSequence(0)
print(await sequence.element)

await stream.yield(1)
print(await sequence.element)

await stream.yield(2)
await stream.yield(3)
await stream.yield(4)
print(await sequence.element)

// Prints:
// 0
// 1
// 4
  • The element wrapped by this async sequence, emitted as a new element whenever it changes.

    Declaration

    Swift

    public private(set) var element: Element { get }

Initialization

  • Creates an async sequence that emits elements only after a specified time interval elapses between emissions.

    Declaration

    Swift

    public init(_ element: Element)

    Parameters

    element

    The async sequence in which this sequence receives it’s elements.

AsyncSequence

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

    Declaration

    Swift

    nonisolated public func makeAsyncIterator() -> AsyncStream<Element>.Iterator

    Return Value

    An instance that conforms to AsyncIteratorProtocol.

API

  • Yield a new element to the sequence.

    Yielding a new element will update this async sequence’s element property along with emitting it through the sequence.

    Declaration

    Swift

    public func yield(_ element: Element)

    Parameters

    element

    The element to yield.

  • Mark the sequence as finished by having it’s iterator emit nil.

    Once finished, any calls to yield will result in no change.

    Declaration

    Swift

    public func finish()
  • Emit one last element beford marking the sequence as finished by having it’s iterator emit nil.

    Once finished, any calls to yield will result in no change.

    Declaration

    Swift

    public func finish(with element: Element)

    Parameters

    element

    The element to emit.