Chan

Channels are the pipes that connect concurrent operations. You can send values into channels from one operation and receive those values into another operation.

var messages = Chan<String>()
dispatch {
    messages <- "ping"
}
if let msg := <-messages {
    println(msg)
}
    • Parameter capacity A value greater than Zero will create a buffered channel.
    • Returns a Chan object

    Declaration

    Swift

    public init(_ capacity: Int = 0)
  • The number of elements queued (unread) in the channel buffer

    Declaration

    Swift

    public func count() -> Int
  • The channel buffer capacity, in units of elements;

    Declaration

    Swift

    public func capacity() -> Int
  • Closes the channel. It should be executed only by the sender, never the receiver, and has the effect of shutting down the channel after the last sent value is received. After the last value has been received from a closed channel, any receive from the channel will succeed without blocking, returning the a nil value for the channel element.

    Declaration

    Swift

    public func close()