Struct async_local::runtime::Builder  
source · pub struct Builder { /* private fields */ }Available on crate features 
tokio-runtime or barrier-protected-runtime only.Expand description
Builds Tokio runtime configured with a shutdown barrier
Implementations§
source§impl Builder
 
impl Builder
sourcepub fn new_current_thread() -> Builder
 
pub fn new_current_thread() -> Builder
Returns a new builder with the current thread scheduler selected.
sourcepub fn new_multi_thread() -> Builder
 
pub fn new_multi_thread() -> Builder
Returns a new builder with the multi thread scheduler selected.
sourcepub fn enable_all(&mut self) -> &mut Self
 
pub fn enable_all(&mut self) -> &mut Self
Enables both I/O and time drivers.
sourcepub fn worker_threads(&mut self, val: usize) -> &mut Self
 
pub fn worker_threads(&mut self, val: usize) -> &mut Self
Sets the number of worker threads the Runtime will use.
This can be any number above 0 though it is advised to keep this value on the smaller side.
This will override the value read from environment variable TOKIO_WORKER_THREADS.
Default
The default value is the number of cores available to the system.
When using the current_thread runtime this method has no effect.
Examples
Multi threaded runtime with 4 threads
use async_local::runtime;
// This will spawn a work-stealing runtime with 4 worker threads.
let rt = runtime::Builder::new_multi_thread()
  .worker_threads(4)
  .build()
  .unwrap();
rt.spawn(async move {});Current thread runtime (will only run on the current thread via Runtime::block_on)
use async_local::runtime;
// Create a runtime that _must_ be driven from a call
// to `Runtime::block_on`.
let rt = runtime::Builder::new_current_thread().build().unwrap();
// This will run the runtime and future on the current thread
rt.block_on(async move {});Panics
This will panic if val is not larger than 0.