ChannelWriter

public class ChannelWriter<T>

The ChannelWriter class writes values to a channel. It’s a reference type so Channels have a common object to add handlers to.

  • Initializes an empty ChannelWriter

    Declaration

    Swift

    public init()
  • Declaration

    Swift

    public func addHandler(handler: T -> ())

    Parameters

    handler

    A function to be called when a value is written.

  • Asynchronously and concurrently writes a value to all attached handlers.

    Note

    If the queue passed is not concurrent, handlers will not be called concurrently.

    Declaration

    Swift

    public func write(
            value: T, queue: DispatchQueue = Dispatch.globalQueue
        ) -> Future<()>

    Parameters

    value

    The value to write

    queue

    The queue to execute handlers on

    Return Value

    A Future that will complete when all handlers have exited.

  • A Channel which will receive values written to this writer.

    Declaration

    Swift

    public var channel: Channel<T>