Oneshot future mpsc channel


I’d like to select between channel output and future and then dropping the channel if not needed, so the channel’s writer would know that channel is closed.

Since oneshot channel has internal buffer, it is possible to have a race between wiriting to channel and dropping it.

How to correctly handle such cases?
Maybe there is another way to describe such behaviour?



I think that the best way to handle such cases is to use multi producer oneshot with future api.
Since current futures::oneshot is single producer, I wrote multi producer implementation. It’s simple and cost only one additional Arc.

Usage example(won’t compile):

Problem is that oneshot implementation uses futures::lock which is private, so only way to use it is to copy implementation.