Oneshot future mpsc channel

#1

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?

Example: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=a95fb73e71720060f3a98f2ae4f0098f

#2

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): https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=4b8f4adcbda5918490f57187731ba0a2

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