Struct Runtime
pub struct Runtime { /* private fields */ }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
impl Runtime
pub fn builder() -> RuntimeBuilder
pub fn builder() -> RuntimeBuilder
Create a builder for Runtime.
pub fn driver_type(&self) -> DriverType
pub fn driver_type(&self) -> DriverType
The current driver type.
pub fn try_with_current<T, F>(f: F) -> Result<T, F>
pub fn try_with_current<T, F>(f: F) -> Result<T, F>
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
pub fn with_current<T, F>(f: F) -> T
pub fn try_current() -> Option<Runtime>
pub fn try_current() -> Option<Runtime>
Try to get the current runtime, and if no runtime is running, return
None.
pub fn enter<T, F>(&self, f: F) -> Twhere
F: FnOnce() -> T,
pub fn enter<T, F>(&self, f: F) -> Twhere
F: FnOnce() -> T,
Set this runtime as current runtime, and perform a function in the current scope.
pub fn run(&self) -> bool
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
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>::Outputwhere
F: Future,
pub fn block_on<F>(&self, future: F) -> <F as Future>::Outputwhere
F: Future,
Block on the future till it completes.
pub fn block_on_at<F>(
&self,
future: F,
meta: SpawnMeta,
) -> <F as Future>::Outputwhere
F: Future,
pub fn block_on_at<F>(
&self,
future: F,
meta: SpawnMeta,
) -> <F as Future>::Outputwhere
F: Future,
Block on the future till it completes, attributing the task it shows up
as in the console to the given SpawnMeta.
This is for the runtimes compio blocks on itself, whose location points into compio rather than into the code of whoever set them running.
pub fn spawn<F>(&self, future: F) -> JoinHandle<<F as Future>::Output> ⓘwhere
F: Future + 'static,
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_at<F>(
&self,
future: F,
meta: SpawnMeta,
) -> JoinHandle<<F as Future>::Output> ⓘwhere
F: Future + 'static,
pub fn spawn_at<F>(
&self,
future: F,
meta: SpawnMeta,
) -> JoinHandle<<F as Future>::Output> ⓘwhere
F: Future + 'static,
Spawns a new asynchronous task, attributing it to meta instead of to
the caller.
Wrappers around spawn can use meta to track the original
caller, so that tokio-console blames that caller instead of the
wrapper. SpawnMeta only matters to the console, and is a
zero-sized no-op without the console feature.
pub fn num_alive_tasks(&self) -> usize
pub fn num_alive_tasks(&self) -> usize
Returns the number of alive tasks in the runtime.
This counts the tasks created by spawn and spawn_blocking that
have not finished yet, whether they are scheduled to run or waiting to
be woken. The future passed to block_on is not a task and is not
counted.
A finished or cancelled task stops being counted once the runtime has
run it for the last time, which may be later than the moment its
JoinHandle reports it.
pub fn spawn_blocking<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T> ⓘwhere
T: Send + 'static,
pub fn spawn_blocking<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
) -> JoinHandle<T> ⓘwhere
T: Send + 'static,
Spawns a blocking task in the driver’s thread pool, returning a handle for it.
This thread pool is limited, and is also used by the driver for
operations that don’t have native asynchronous support. See
ProactorBuilder::thread_pool_limit. If all the threads are busy
when the task is submitted, the runtime thread blocks until one is
available.
The task can be cancelled by dropping the returned JoinHandle, but
the execution won’t be interrupted if already started. In that case,
it runs to completion and the result is discarded.
pub fn spawn_blocking_at<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
meta: SpawnMeta,
) -> JoinHandle<T> ⓘwhere
T: Send + 'static,
pub fn spawn_blocking_at<T>(
&self,
f: impl FnOnce() -> T + Send + 'static,
meta: SpawnMeta,
) -> JoinHandle<T> ⓘwhere
T: Send + 'static,
Spawns a blocking task in the driver’s thread pool, attributing it to
meta instead of to the caller. See spawn_blocking for details.
See spawn_at for what meta is good for.
pub fn attach(&self, fd: i32) -> Result<(), Error>
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,
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,
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
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>
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)
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>)
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>
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>
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>
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>
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>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl !UnwindSafe for Runtime
impl Forget for Runtime
impl Freeze for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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