Mpsc Receiver getting dropped after being passed into a futures combinator

#1

So I’m writing this plugin for a program that facilitates websockets. I’ve almost finished but I hit a brick wall with a receiver getting dropped.

Basically, there are two channels, one is a stdlib one that simply acts as a queue when new data arrives, so the host app’s event loop can query it and trigger callbacks. The second one is for when the host app needs to send data on the websocket.

The problem is, this one is somehow getting dropped and I get this error at runtime:

send failed because receiver is gone

On this line:

where the host app calls to send some data to the channel which is consumed by the futures combinator spaghetti.

I’ve been trying to figure this one out for a while now - I thought my combinator code was wrong so I even rewrote the entire thing but I can’t seem to solve it. I don’t know how the receiver is being dropped, it’s moved into the combinator closure and used to forward data to the stream sink.

Would love to get this last piece of the puzzle solved, thanks!

#2

This looks off - you should not be wait()'ing for a future inside your chain of futures. Instead, that future (or some continuation on top of it) needs to be fed to the event loop/reactor, and let it run it to completion.

As it happens, I think your entire and_then just completes, and the receiver is dropped.

#3

This makes sense now, I’ve been using it wrong.

The problem is, I have no idea how to construct the right set of combinators to do what I want. I need to forward stream to incoming_send and outgoing_recv to sink - that’s all. But I can’t seem to do this, anything I try results in really obscure trait errors.