pub struct RuntimeCompat<A> { /* private fields */ }Expand description
A compatibility layer for [Runtime]. It is driven by the underlying
Adapter.
Implementations§
Source§impl<A: Adapter> RuntimeCompat<A>
impl<A: Adapter> RuntimeCompat<A>
Sourcepub fn new(runtime: Runtime) -> Result<Self>
pub fn new(runtime: Runtime) -> Result<Self>
Creates a new RuntimeCompat with the given runtime.
Methods from Deref<Target = Runtime>§
pub fn driver_type(&self) -> DriverType
pub fn driver_type(&self) -> DriverType
The current driver type.
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: *mut c_void) -> Result<(), Error>
pub fn attach(&self, fd: *mut c_void) -> 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: &[*mut c_void]) -> Result<(), Error>
pub fn register_files(&self, fds: &[*mut c_void]) -> 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<A> Forget for RuntimeCompat<A>
impl<A> Freeze for RuntimeCompat<A>where
A: Freeze,
impl<A> RefUnwindSafe for RuntimeCompat<A>where
A: RefUnwindSafe,
impl<A> Send for RuntimeCompat<A>where
A: Send,
impl<A> Sync for RuntimeCompat<A>where
A: Sync,
impl<A> Unpin for RuntimeCompat<A>where
A: Unpin,
impl<A> UnsafeUnpin for RuntimeCompat<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for RuntimeCompat<A>where
A: UnwindSafe,
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
§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