diff options
author | Carl Lerche <me@carllerche.com> | 2019-11-12 15:23:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-12 15:23:40 -0800 |
commit | 27e5b41067d01c0c9fac230c5addb58034201a63 (patch) | |
tree | f9bd8333dfe1853dfe1d8710b4dc966bd8555d54 /tokio/src/fs | |
parent | e3df2eafd32e6f813d08617f0e2cd7abbc05c2b1 (diff) |
reorganize modules (#1766)
This patch started as an effort to make `time::Timer` private. However, in an
effort to get the build compiling again, more and more changes were made. This
probably should have been broken up, but here we are. I will attempt to
summarize the changes here.
* Feature flags are reorganized to make clearer. `net-driver` becomes
`io-driver`. `rt-current-thread` becomes `rt-core`.
* The `Runtime` can be created without any executor. This replaces `enter`. It
also allows creating I/O / time drivers that are standalone.
* `tokio::timer` is renamed to `tokio::time`. This brings it in line with `std`.
* `tokio::timer::Timer` is renamed to `Driver` and made private.
* The `clock` module is removed. Instead, an `Instant` type is provided. This
type defaults to calling `std::time::Instant`. A `test-util` feature flag can
be used to enable hooking into time.
* The `blocking` module is moved to the top level and is cleaned up.
* The `task` module is moved to the top level.
* The thread-pool's in-place blocking implementation is cleaned up.
* `runtime::Spawner` is renamed to `runtime::Handle` and can be used to "enter"
a runtime context.
Diffstat (limited to 'tokio/src/fs')
-rw-r--r-- | tokio/src/fs/blocking.rs | 6 | ||||
-rw-r--r-- | tokio/src/fs/file.rs | 10 | ||||
-rw-r--r-- | tokio/src/fs/mod.rs | 12 | ||||
-rw-r--r-- | tokio/src/fs/read_dir.rs | 2 |
4 files changed, 19 insertions, 11 deletions
diff --git a/tokio/src/fs/blocking.rs b/tokio/src/fs/blocking.rs index 3a9f754c..695358a3 100644 --- a/tokio/src/fs/blocking.rs +++ b/tokio/src/fs/blocking.rs @@ -74,7 +74,7 @@ where })); } Busy(ref mut rx) => { - let (res, mut buf, inner) = ready!(Pin::new(rx).poll(cx)); + let (res, mut buf, inner) = ready!(Pin::new(rx).poll(cx))?; self.inner = Some(inner); match res { @@ -126,7 +126,7 @@ where return Ready(Ok(n)); } Busy(ref mut rx) => { - let (res, buf, inner) = ready!(Pin::new(rx).poll(cx)); + let (res, buf, inner) = ready!(Pin::new(rx).poll(cx))?; self.state = Idle(Some(buf)); self.inner = Some(inner); @@ -158,7 +158,7 @@ where } } Busy(ref mut rx) => { - let (res, buf, inner) = ready!(Pin::new(rx).poll(cx)); + let (res, buf, inner) = ready!(Pin::new(rx).poll(cx))?; self.state = Idle(Some(buf)); self.inner = Some(inner); diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index 9b81a278..3f18831e 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -223,7 +223,7 @@ impl File { let (op, buf) = match self.state { Idle(_) => unreachable!(), - Busy(ref mut rx) => rx.await, + Busy(ref mut rx) => rx.await.unwrap(), }; self.state = Idle(Some(buf)); @@ -343,7 +343,7 @@ impl File { let (op, buf) = match self.state { Idle(_) => unreachable!(), - Busy(ref mut rx) => rx.await, + Busy(ref mut rx) => rx.await?, }; self.state = Idle(Some(buf)); @@ -464,7 +464,7 @@ impl AsyncRead for File { })); } Busy(ref mut rx) => { - let (op, mut buf) = ready!(Pin::new(rx).poll(cx)); + let (op, mut buf) = ready!(Pin::new(rx).poll(cx))?; match op { Operation::Read(Ok(_)) => { @@ -537,7 +537,7 @@ impl AsyncWrite for File { return Ready(Ok(n)); } Busy(ref mut rx) => { - let (op, buf) = ready!(Pin::new(rx).poll(cx)); + let (op, buf) = ready!(Pin::new(rx).poll(cx))?; self.state = Idle(Some(buf)); match op { @@ -570,7 +570,7 @@ impl AsyncWrite for File { let (op, buf) = match self.state { Idle(_) => return Ready(Ok(())), - Busy(ref mut rx) => ready!(Pin::new(rx).poll(cx)), + Busy(ref mut rx) => ready!(Pin::new(rx).poll(cx))?, }; // The buffer is not used here diff --git a/tokio/src/fs/mod.rs b/tokio/src/fs/mod.rs index ed3b4162..9108116a 100644 --- a/tokio/src/fs/mod.rs +++ b/tokio/src/fs/mod.rs @@ -84,12 +84,20 @@ where F: FnOnce() -> io::Result<T> + Send + 'static, T: Send + 'static, { - sys::run(f).await + match sys::run(f).await { + Ok(res) => res, + Err(_) => Err(io::Error::new( + io::ErrorKind::Other, + "background task failed", + )), + } } /// Types in this module can be mocked out in tests. mod sys { pub(crate) use std::fs::File; - pub(crate) use crate::runtime::blocking::{run, Blocking}; + // TODO: don't rename + pub(crate) use crate::blocking::spawn_blocking as run; + pub(crate) use crate::task::JoinHandle as Blocking; } diff --git a/tokio/src/fs/read_dir.rs b/tokio/src/fs/read_dir.rs index 0fd5bf0b..9492a2f4 100644 --- a/tokio/src/fs/read_dir.rs +++ b/tokio/src/fs/read_dir.rs @@ -65,7 +65,7 @@ impl Stream for ReadDir { })); } State::Pending(ref mut rx) => { - let (ret, std) = ready!(Pin::new(rx).poll(cx)); + let (ret, std) = ready!(Pin::new(rx).poll(cx))?; self.0 = State::Idle(Some(std)); let ret = ret.map(|res| res.map(|std| DirEntry(Arc::new(std)))); |