The Channel type is Keid's equivalent to Golang's chan. Channels are:
Asynchronously blocking: if there is data buffered in the channel to be read immediately, one value is dequeued and returned, and the microthread continues executing. Otherwise, if no data is immediately ready, microthreads are paused by the Keid runtime until another microthread writes data to the channel.
Closeable: once a channel is closed, reading or writing to it results in a runtime exception. The closed getter field on the Channel<T> type returns whether or not the channel has been closed, and a channel can be closed via the Channel.close() method.
Directional: a send-receive channel can be cast down to a send-only or receive-only channel for the purpose of encapsulation. Channels cannot be cast back to send-receive or between send-only and receive-only (i.e. sendonly Channel<T> or readonly Channel<T>).
Conditional: channel reads can be simultaneous, returning the value from the first channel to send data, and cancelling reading all the other channels. This is akin to the select operator in Golang.
The
Channel
type is Keid's equivalent to Golang'schan
. Channels are:closed
getter field on theChannel<T>
type returns whether or not the channel has been closed, and a channel can be closed via theChannel.close()
method.sendonly Channel<T>
orreadonly Channel<T>
).select
operator in Golang.