Sender

public final class Sender
extension CoChannel.Sender: CoCancellable

A CoChannel wrapper that provides send-only functionality.

  • The type of channel buffer.

    Declaration

    Swift

    @inlinable
    public var bufferType: BufferType { get }
  • Returns a number of elements in this channel.

    Declaration

    Swift

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

    Declaration

    Swift

    @inlinable
    public var isEmpty: Bool { get }

send

  • Sends the element to this channel, suspending the coroutine while the buffer of this channel is full. Must be called inside a coroutine.

    Throws

    CoChannelError when canceled or closed.

    Declaration

    Swift

    @inlinable
    public func awaitSend(_ element: Element) throws

    Parameters

    element

    Value that will be sent to the channel.

  • Adds the future’s value to this channel when it will be available.

    Declaration

    Swift

    @inlinable
    public func sendFuture(_ future: CoFuture<Element>)

    Parameters

    future

    CoFuture‘s value that will be sent to the channel.

  • Immediately adds the value to this channel, if this doesn’t violate its capacity restrictions, and returns true. Otherwise, just returns false.

    Declaration

    Swift

    @discardableResult
    @inlinable
    public func offer(_ element: Element) -> Bool

    Parameters

    element

    Value that might be sent to the channel.

    Return Value

    true if sent successfully or false if channel buffer is full or channel is closed or canceled.

close

  • Closes this channel. No more send should be performed on the channel.

    Declaration

    Swift

    @discardableResult
    @inlinable
    public func close() -> Bool

    Return Value

    true if closed successfully or false if channel is already closed or canceled.

  • Returns true if the channel is closed.

    Declaration

    Swift

    @inlinable
    public var isClosed: Bool { get }

cancel

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public 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

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

    Parameters

    callback

    The callback that is called when the CoChannel is completed.