pub struct Builder { /* private fields */ }
Available on crate feature
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
.
Auto Trait Implementations§
impl !Freeze for Builder
impl !RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl !UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more