Basic sends and receives on channels are blocking in Elixir. However, we can use receive with a after clause to implement non-blocking receives, and send with Process.info(self(), :message_queue_len) to implement non-blocking sends.
To run the program:
In this Elixir version, we use processes to simulate channels. The spawn function creates new processes that run the receive_loop function, which keeps the processes alive and ready to receive messages.
We use receive with an after 0 clause to implement non-blocking receives. For non-blocking sends, we send the message and then check the process mailbox length to determine if the message was sent successfully.
The multi-way non-blocking select is implemented using multiple patterns in the receive block, followed by an after 0 clause for the default case.
Note that Elixir’s concurrency model is based on the actor model, which is somewhat different from Go’s channel-based concurrency. However, this example demonstrates how to achieve similar non-blocking operations in Elixir.