Forwarding from a futures::Stream to a futures::Sink

寵の児 提交于 2019-12-08 15:29:35

问题


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?

来源:https://stackoverflow.com/questions/44990227/forwarding-from-a-futuresstream-to-a-futuressink

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!