I’ve been experimenting with something along the lines of Rust’s MPSC (multi-producer/single-consumer) channels. The result is here. With this shard you can still call
receive just like with plain
Channels, and if you want to do a non-blocking receive you call
Part of this experiment was based on the frustration some of us felt when things like
Channel#empty? were removed from the API and I finally decided to create this shard instead of using code like
channel.@queue.empty? any time I didn’t want to block when there were no items in the channel.
To be clear, I think removing methods like
Channel#empty? was a good decision because they gave a false sense of security when you were consuming the same channel on multiple fibers. Most of my own use cases for channels in Crystal are consuming from a single fiber, though, and it seems a few other members of the Crystal community do the same. And one of the nice things about consuming from a single fiber is that you don’t have to worry about race conditions that the stdlib
Channel insulates us from.