How to implement a file stream in futures 0.2?


#1

In futures 0.1, I can use CpuPool to spawn a reading task, then get the result by polling CpuFuture<...> for each chunk, but seems this way not available in futures 0.2, the ThreadPool::run(...) will block the thread until the task finish.

My thought is to wrap the oneshot::channel, use the oneshot::Sender<io::Result<File, BytesMut>> to get the reading result for each chunk. I want to know any other graceful way to do that.


#2

ThreadPool still provides “spawn” (it became part of the “Executor” trait, though).

Run works differently: it runs a future to completion, but it may spawn any additional tasks which will be detached. That allows you to express “spawn N items, even if we can just work on 4 in parallel, return if all are spawned”.