Channels

  • A channel is a synchronization primitive.

    Threads

    You can use Venice in multi-threaded programs. However, individual threads are strictly separated. You may think of each thread as a separate process.

    In particular, a coroutine created in a thread will be executed in that same thread, and it will never migrate to a different one.

    In a similar manner, a handle, such as a channel or a coroutine handle, created in one thread cannot be used in a different thread.

    Example:

    let channel = Channel<Int>()
    
    let coroutine = try Coroutine {
        try channel.send(42, deadline: 1.second.fromNow())
    }
    
    let theAnswer = try channel.receive(deadline: 1.second.fromNow())
    try coroutine.close()
    
    See more

    Declaration

    Swift

    public final class Channel<Type> : Handle