Receiver

public class Receiver
extension CoChannel.Receiver: CoCancellable

A CoChannel wrapper that provides receive-only functionality.

  • The type of channel buffer.

    Declaration

    Swift

    public var bufferType: BufferType { get }

receive

  • Retrieves and removes an element from this channel if it’s not empty, or suspends a coroutine while the channel is empty.

    Throws

    CoChannelError when canceled or closed.

    Declaration

    Swift

    public func awaitReceive() throws -> Element

    Return Value

    Removed value from the channel.

  • Creates CoFuture with retrieved value from this channel.

    Declaration

    Swift

    @inlinable
    public final func receiveFuture() -> CoFuture<Element>

    Return Value

    CoFuture with a future value from the channel.

  • Retrieves and removes an element from this channel.

    Declaration

    Swift

    public func poll() -> Element?

    Return Value

    Element from this channel if its not empty, or returns nill if the channel is empty or is closed or canceled.

  • Adds an observer callback to receive an element from this channel.

    Declaration

    Swift

    public func whenReceive(_ callback: @escaping (Result<Element, CoChannelError>) -> Void)

    Parameters

    callback

    The callback that is called when a value is received.

  • Returns a number of elements in this channel.

    Declaration

    Swift

    public var count: Int { get }
  • Returns true if the channel is empty (contains no elements), which means no elements to receive.

    Declaration

    Swift

    public var isEmpty: Bool { get }

map

  • Returns new Receiver that provides transformed values from this CoChannel.

    Declaration

    Swift

    public final func map<T>(_ transform: @escaping (Element) -> T) -> CoChannel<T>.Receiver

    Parameters

    transform

    A mapping closure.

    Return Value

    A Receiver with transformed values.

close

  • Returns true if the channel is closed.

    Declaration

    Swift

    public var isClosed: Bool { get }

cancel

  • Closes the channel and removes all buffered sent elements from it.

    Declaration

    Swift

    public func cancel()
  • Returns true if the channel is canceled.

    Declaration

    Swift

    public var isCanceled: Bool { get }
  • Adds an observer callback that is called when the CoChannel is canceled.

    Declaration

    Swift

    public final func whenCanceled(_ callback: @escaping () -> Void)

    Parameters

    callback

    The callback that is called when the CoChannel is canceled.

complete

  • Adds an observer callback that is called when the CoChannel is completed (closed, canceled or deinited).

    Declaration

    Swift

    public final func whenComplete(_ callback: @escaping () -> Void)

    Parameters

    callback

    The callback that is called when the CoChannel is completed.

sequence

  • Make an iterator which successively retrieves and removes values from the channel.

    If next() was called inside a coroutine and there are no more elements in the channel, then the coroutine will be suspended until a new element will be added to the channel or it will be closed or canceled.

    Declaration

    Swift

    @inlinable
    public func makeIterator() -> AnyIterator<Element>

    Return Value

    Iterator for the channel elements.

publisher

  • Returns a publisher that emits elements of this Receiver.

    Declaration

    Swift

    public func publisher() -> AnyPublisher<Element, CoChannelError>