Sender

public final class Sender<C> : Cancellable where C : ChannelProtocol
  • Declaration

    Swift

    public typealias Item = C.Buffer.Item
  • Declaration

    Swift

    @inlinable
    public var capacity: Int { get }
  • Sends item into the channel.

    Declaration

    Swift

    @inlinable
    public func trySend(_ item: Item) -> Result<Bool, Channel.Error>

    Return Value

    • Result.success(true) if item was sent successfully.
    • Result.success(false) if the channel is at capacity.
    • Result.failure if the channel is closed.

  • Declaration

    Swift

    @inlinable
    public func tryFlush() -> Result<Bool, Channel.Error>

    Return Value

    • Result.success(true) if the channel is empty.
    • Result.success(false) if the channel is not empty.
    • Result.failure if the channel is closed.

  • Closes the channel, preventing senders from sending new items.

    Items sent before a call to this function can still be consumed by the receiver, until the channel is flushed. After the last item is consumed, subsequent attempts to receive an item will fail with Channel.Error.cancelled.

    It is acceptable to call this method more than once; subsequent calls are just ignored.

    Declaration

    Swift

    @inlinable
    public func cancel()
  • Sends item into the channel.

    Declaration

    Swift

    @discardableResult
    @inlinable
    public func send(_ item: Item) -> Result<Void, Channel.Error>

    Return Value

    • Result.success if item was sent successfully.
    • Result.failure if the channel is closed.