diff options
author | Steven Fackler <sfackler@gmail.com> | 2018-09-28 21:00:50 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2018-09-28 21:00:50 -0700 |
commit | d06bd6b2169cfae5323181cc5c28e0a2fa28e69c (patch) | |
tree | d88f11d21df0c3fbef375a163021534ce8a85625 /src | |
parent | 2c85cd09914305a173c6a7467ed0cf90d9049d11 (diff) |
Expose keep_alive on the Runtime builder (#676)
This was overlooked when delegating the rest of the threadpool builder
methods from Runtime's builder.
Diffstat (limited to 'src')
-rw-r--r-- | src/runtime/builder.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/runtime/builder.rs b/src/runtime/builder.rs index 43eb5dde..d09f08bf 100644 --- a/src/runtime/builder.rs +++ b/src/runtime/builder.rs @@ -3,6 +3,7 @@ use runtime::{Inner, Runtime}; use reactor::Reactor; use std::io; +use std::time::Duration; use tokio_reactor; use tokio_threadpool::Builder as ThreadPoolBuilder; @@ -79,7 +80,8 @@ impl Builder { #[deprecated( since="0.1.9", note="use the `core_threads`, `blocking_threads`, `name_prefix`, \ - and `stack_size` functions on `runtime::Builder`, instead")] + `keep_alive`, and `stack_size` functions on `runtime::Builder`, \ + instead")] #[doc(hidden)] pub fn threadpool_builder(&mut self, val: ThreadPoolBuilder) -> &mut Self { self.threadpool_builder = val; @@ -142,6 +144,37 @@ impl Builder { self } + /// Set the worker thread keep alive duration for threads in the `Runtime`'s + /// thread pool. + /// + /// If set, a worker thread will wait for up to the specified duration for + /// work, at which point the thread will shutdown. When work becomes + /// available, a new thread will eventually be spawned to replace the one + /// that shut down. + /// + /// When the value is `None`, the thread will wait for work forever. + /// + /// The default value is `None`. + /// + /// # Examples + /// + /// ``` + /// # extern crate tokio; + /// # extern crate futures; + /// # use tokio::runtime; + /// use std::time::Duration; + /// + /// # pub fn main() { + /// let mut rt = runtime::Builder::new() + /// .keep_alive(Some(Duration::from_secs(30))) + /// .build(); + /// # } + /// ``` + pub fn keep_alive(&mut self, val: Option<Duration>) -> &mut Self { + self.threadpool_builder.keep_alive(val); + self + } + /// Set name prefix of threads spawned by the `Runtime`'s thread pool. /// /// Thread name prefix is used for generating thread names. For example, if |