diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/runtime.rs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/runtime.rs b/src/runtime.rs index 1b4a83dd..3fb3c9aa 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -339,17 +339,7 @@ impl Runtime { /// [mod]: index.html pub fn shutdown_now(mut self) -> Shutdown { let inner = self.inner.take().unwrap(); - - let inner = Box::new({ - let pool = inner.pool; - let reactor = inner.reactor; - - pool.shutdown_now().and_then(|_| { - reactor.shutdown_now() - }) - }); - - Shutdown { inner } + Shutdown::shutdown_now(inner) } fn inner(&self) -> &Inner { @@ -361,6 +351,15 @@ impl Runtime { } } +impl Drop for Runtime { + fn drop(&mut self) { + if let Some(inner) = self.inner.take() { + let shutdown = Shutdown::shutdown_now(inner); + let _ = shutdown.wait(); + } + } +} + // ===== impl TaskExecutor ===== impl TaskExecutor { @@ -425,6 +424,24 @@ impl ::executor::Executor for TaskExecutor { // ===== impl Shutdown ===== +impl Shutdown { + fn shutdown_now(inner: Inner) -> Self { + let inner = Box::new({ + let pool = inner.pool; + let reactor = inner.reactor; + + pool.shutdown_now().and_then(|_| { + reactor.shutdown_now() + .then(|_| { + Ok(()) + }) + }) + }); + + Shutdown { inner } + } +} + impl Future for Shutdown { type Item = (); type Error = (); |