pub struct TokioRuntimeBuilder { /* private fields */ }
Expand description
Builds a compatibility runtime with custom configuration values.
This runtime is compatible with code using both the current release version
of tokio
(0.1) and with legacy code using tokio
0.1.
Methods can be chained in order to set the configuration values. The
Runtime is constructed by calling build
.
New instances of Builder
are obtained via Builder::new
.
See function level documentation for details on the various configuration settings.
§Examples
use tokio_compat::runtime::Builder;
use tokio_timer_02::clock::Clock;
fn main() {
// build Runtime
let runtime = Builder::new()
.clock(Clock::system())
.core_threads(4)
.name_prefix("my-custom-name-")
.stack_size(3 * 1024 * 1024)
.build()
.unwrap();
// use runtime ...
}
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn new() -> Builder
pub fn new() -> Builder
Returns a new runtime builder initialized with default configuration values.
Configuration methods can be chained on the return value.
Sourcepub fn clock(&mut self, clock: Clock) -> &mut Builder
pub fn clock(&mut self, clock: Clock) -> &mut Builder
Set the Clock
instance that will be used by the runtime’s legacy timer.
Sourcepub fn core_threads(&mut self, val: usize) -> &mut Builder
pub fn core_threads(&mut self, val: usize) -> &mut Builder
Set the maximum number of worker threads for the Runtime
’s thread pool.
This must be a number between 1 and 32,768 though it is advised to keep this value on the smaller side.
The default value is the number of cores available to the system.
§Examples
let rt = runtime::Builder::new()
.core_threads(4)
.build()
.unwrap();
Sourcepub fn name_prefix<S>(&mut self, val: S) -> &mut Builder
pub fn name_prefix<S>(&mut self, val: S) -> &mut Builder
Set name prefix of threads spawned by the Runtime
’s thread pool.
Thread name prefix is used for generating thread names. For example, if
prefix is my-pool-
, then threads in the pool will get names like
my-pool-1
etc.
The default prefix is “tokio-runtime-worker-”.
§Examples
let rt = runtime::Builder::new()
.name_prefix("my-pool-")
.build();
Sourcepub fn stack_size(&mut self, val: usize) -> &mut Builder
pub fn stack_size(&mut self, val: usize) -> &mut Builder
Set the stack size (in bytes) for worker threads.
The actual stack size may be greater than this value if the platform specifies minimal stack size.
The default stack size for spawned threads is 2 MiB, though this particular stack size is subject to change in the future.
§Examples
let rt = runtime::Builder::new()
.stack_size(32 * 1024)
.build();