import { Channel } from "https://deno.land/x/ayonli_jsext@v0.9.72/chan.ts";
A channel implementation that transfers data across routines, even across multiple threads, inspired by Golang.
Methods
Closes the channel. If err
is supplied, it will be captured by the
receiver.
No more data shall be sent once the channel is closed.
Explicitly closing the channel is not required, if the channel is no
longer used, it will be automatically released by the GC. However, if
the channel is used in a for await...of...
loop, closing the channel
will allow the loop to break automatically.
Moreover, if the channel is used between parallel threads, it will no longer be able to release automatically, must explicitly call this function in order to release for GC.
Retrieves data from the channel.
If there isn't data available at the moment, this function will block until new data is available.
If the channel is closed, then:
- If there is error set in the channel, this function throws that error immediately.
- Otherwise, this function returns
undefined
immediately.
Pushes data to the channel.
If there is a receiver, the data will be consumed immediately. Otherwise:
-
If this is an non-buffered channel, this function will block until a receiver is available and the data is consumed.
-
If this is a buffered channel, then:
- If the buffer size is within the capacity, the data will be pushed to the buffer.
- Otherwise, this function will block until there is new space for the data in the buffer.