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

source

pub fn new_current_thread() -> Builder

Returns a new builder with the current thread scheduler selected.

source

pub fn new_multi_thread() -> Builder

Returns a new builder with the multi thread scheduler selected.

source

pub fn enable_all(&mut self) -> &mut Self

Enables both I/O and time drivers.

source

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.

source

pub fn build(&mut self) -> Result<Runtime>

Creates a Tokio Runtime configured with a barrier that rendezvous worker threads during shutdown as to ensure tasks never outlive local data owned by worker threads

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.