Skip to main content

Runtime

Struct Runtime 

pub struct Runtime(/* private fields */);
Available on crate feature runtime only.
Expand description

The async runtime of compio.

It is a thread-local runtime, meaning it cannot be sent to other threads.

Implementations§

§

impl Runtime

pub fn new() -> Result<Runtime, Error>

Create Runtime with default config.

pub fn builder() -> RuntimeBuilder

Create a builder for Runtime.

pub fn driver_type(&self) -> DriverType

The current driver type.

pub fn try_with_current<T, F>(f: F) -> Result<T, F>
where F: FnOnce(&Runtime) -> T,

Try to perform a function on the current runtime, and if no runtime is running, return the function back.

pub fn with_current<T, F>(f: F) -> T
where F: FnOnce(&Runtime) -> T,

Perform a function on the current runtime.

§Panics

This method will panic if there is no running Runtime.

pub fn try_current() -> Option<Runtime>

Try to get the current runtime, and if no runtime is running, return None.

pub fn current() -> Runtime

Get the current runtime.

§Panics

This method will panic if there is no running Runtime.

pub fn enter<T, F>(&self, f: F) -> T
where F: FnOnce() -> T,

Set this runtime as current runtime, and perform a function in the current scope.

pub fn run(&self) -> bool

Low level API to control the runtime.

Run the scheduled tasks.

The return value indicates whether there are still tasks in the queue.

pub fn waker(&self) -> Waker

Low level API to control the runtime.

Create a waker that always notifies the runtime when woken.

pub fn block_on<F>(&self, future: F) -> <F as Future>::Output
where F: Future,

Block on the future till it completes.

pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output>
where F: Future + 'static,

Spawns a new asynchronous task, returning a JoinHandle for it.

Spawning a task enables the task to execute concurrently to other tasks. There is no guarantee that a spawned task will execute to completion.

pub fn spawn_blocking<T>( &self, f: impl FnOnce() -> T + Send + 'static, ) -> JoinHandle<T>
where T: Send + 'static,

Spawns a blocking task in a new thread, and wait for it.

The task will not be cancelled even if the future is dropped.

pub fn attach(&self, fd: i32) -> Result<(), Error>

Attach a raw file descriptor/handle/socket to the runtime.

You only need this when authoring your own high-level APIs. High-level resources in this crate are attached automatically.

pub fn submit<T>(&self, op: T) -> Submit<T>
where T: OpCode + 'static,

Submit an operation to the runtime.

You only need this when authoring your own OpCode.

pub fn submit_multi<T>(&self, op: T) -> SubmitMulti<T>
where T: OpCode + 'static,

Submit a multishot operation to the runtime.

You only need this when authoring your own OpCode.

pub fn flush(&self) -> bool

Flush the driver and return whether the driver has been notified.

See Proactor::flush for more details.

pub fn current_timeout(&self) -> Option<Duration>

Low level API to control the runtime.

Get the timeout value to be passed to Proactor::poll.

pub fn poll(&self)

Low level API to control the runtime.

Poll the inner proactor. It is equal to calling Runtime::poll_with with Runtime::current_timeout.

pub fn poll_with(&self, timeout: Option<Duration>)

Low level API to control the runtime.

Poll the inner proactor with a custom timeout.

pub fn buffer_pool(&self) -> Result<BufferPool, Error>

Get buffer pool of the runtime.

This will lazily initialize the pool at the first time it’s accessed, and future access to the pool will be cheap and infallible.

pub fn register_files(&self, fds: &[i32]) -> Result<(), Error>

Register file descriptors for fixed-file operations.

This is only supported on io-uring driver, and will return an Unsupported io error on all other drivers.

pub fn unregister_files(&self) -> Result<(), Error>

Unregister previously registered file descriptors.

This is only supported on io-uring driver, and will return an Unsupported io error on all other drivers.

pub fn register_personality(&self) -> Result<u16, Error>

Register the personality for the runtime.

This is only supported on io-uring driver, and will return an Unsupported io error on all other drivers.

The returned personality can be used with FutureExt::with_personality.

pub fn unregister_personality(&self, personality: u16) -> Result<(), Error>

Unregister the given personality for the runtime.

This is only supported on io-uring driver, and will return an Unsupported io error on all other drivers.

Trait Implementations§

§

impl AsRawFd for Runtime

§

fn as_raw_fd(&self) -> i32

Extracts the raw file descriptor. Read more
§

impl AsyncExecutor for &Runtime

Available on crate feature criterion only.
§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
§

impl AsyncExecutor for Runtime

Available on crate feature criterion only.
§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
§

impl Clone for Runtime

§

fn clone(&self) -> Runtime

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Runtime

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Deref for Runtime

§

type Target = RuntimeInner

The resulting type after dereferencing.
§

fn deref(&self) -> &<Runtime as Deref>::Target

Dereferences the value.
§

impl Drop for Runtime

§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more