Skip to content
FutureBlitz

    Install

    Import std.concurrent.channels

    Receive

    std.concurrent.channels

    function

    Public Function Receive<T: Sendable>(channel: Channel<T>, cancel: Cancellation): T? Throws CancelledError

    Receives channel's oldest value, waiting while it has none, unless the cancellation is cancelled first, or is already, which throws a CancelledError and takes none. Null once the Channel is closed and empty, as its Receive gives.

    Examples

    Const channel = Channel<Int>(1)
    Local cancel = Cancellation()
    channel.Send(7)
    Local value = Try Receive(channel, cancel)
    Expect(value == 7)
    cancel.Cancel()
    Expect(ExpectThrows<CancelledError>(Receive(channel, cancel)) != Null)

    std/concurrent/channels.fb, line 36

    Report an issue with this page or with FutureBlitz on GitHub.