diff --git a/Cargo.toml b/Cargo.toml index 03ac446b..6bec796b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ serde_json = "1.0" serde_derive = "1.0" url = "1.7" futures = "0.1" +tokio-threadpool = "0.1" tokio = "0.1" tokio-codec = "0.1" http = "0.1" diff --git a/src/tools/wrapped_reader_stream.rs b/src/tools/wrapped_reader_stream.rs index d930e022..4ad091b7 100644 --- a/src/tools/wrapped_reader_stream.rs +++ b/src/tools/wrapped_reader_stream.rs @@ -1,8 +1,10 @@ use failure::*; +use tokio_threadpool; use tokio::io::{AsyncRead}; use std::io::Read; use futures::Async; use futures::stream::Stream; +use std::io::ErrorKind::{Other, WouldBlock}; pub struct WrappedReaderStream { reader: R, @@ -19,7 +21,12 @@ impl Read for WrappedReaderStream { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { //tokio::io::would_block(|| self.reader.read(buf)) // fixme: howto?? - self.reader.read(buf) + match tokio_threadpool::blocking(|| self.reader.read(buf)) { + Ok(Async::Ready(res)) => res, + Ok(Async::NotReady) => Err(WouldBlock.into()), + Err(err) => Err(std::io::Error::new(Other, "`blocking` annotated I/O must be called \ + from the context of the Tokio runtime.")), + } } }