I am currently trying to wrap my head around the tokio & futures primitives and ecosystem.
I started doing some work from the tk-http websockets example, and wanted to do more processing on the received data rather than echoing it back. A first step seemed to be to replace the .forward() call with some kind of loop.
It seemed to me that stream.forward(sink)
is equivalent to stream.fold(sink, |out_, item| { out.send(item).and_then(Sink::flush) })
, however doing this (commit) the stream is not polled at all. However the same change from the Tokio example works fine (example).
Furthermore, it seems that outputting something on the sink first makes the forwarding work fine (commit), so maybe the sink doesn't get registered with the event loop for some reason until a send happen? Did I miss something? Is it possible it is a bug in tk-http?