pub struct Runtime { /* private fields */ }
Expand description
The async runtime of compio. It is a thread local runtime, and cannot be sent to other threads.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn builder() -> RuntimeBuilder
pub fn builder() -> RuntimeBuilder
Create a builder for Runtime
.
Sourcepub fn try_with_current<T, F: FnOnce(&Self) -> T>(f: F) -> Result<T, F>
pub fn try_with_current<T, F: FnOnce(&Self) -> T>(f: F) -> Result<T, F>
Try to perform a function on the current runtime, and if no runtime is running, return the function back.
Sourcepub fn with_current<T, F: FnOnce(&Self) -> T>(f: F) -> T
pub fn with_current<T, F: FnOnce(&Self) -> T>(f: F) -> T
Sourcepub fn enter<T, F: FnOnce() -> T>(&self, f: F) -> T
pub fn enter<T, F: FnOnce() -> T>(&self, f: F) -> T
Set this runtime as current runtime, and perform a function in the current scope.
Sourcepub 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.
Sourcepub fn block_on<F: Future>(&self, future: F) -> F::Output
pub fn block_on<F: Future>(&self, future: F) -> F::Output
Block on the future till it completes.
Sourcepub fn spawn<F: Future + 'static>(&self, future: F) -> JoinHandle<F::Output>
pub fn spawn<F: Future + 'static>(&self, future: F) -> JoinHandle<F::Output>
Spawns a new asynchronous task, returning a Task
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.
Sourcepub fn spawn_blocking<T: Send + 'static>(
&self,
f: impl FnOnce() -> T + Send + Sync + 'static,
) -> JoinHandle<T>
pub fn spawn_blocking<T: Send + 'static>( &self, f: impl FnOnce() -> T + Send + Sync + 'static, ) -> JoinHandle<T>
Spawns a blocking task in a new thread, and wait for it.
The task will not be cancelled even if the future is dropped.
Sourcepub fn attach(&self, fd: RawFd) -> Result<()>
pub fn attach(&self, fd: RawFd) -> Result<()>
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.
Sourcepub fn submit<T: OpCode + 'static>(
&self,
op: T,
) -> impl Future<Output = BufResult<usize, T>>
pub fn submit<T: OpCode + 'static>( &self, op: T, ) -> impl Future<Output = BufResult<usize, T>>
Submit an operation to the runtime.
You only need this when authoring your own OpCode
.
Sourcepub fn submit_with_flags<T: OpCode + 'static>(
&self,
op: T,
) -> impl Future<Output = (BufResult<usize, T>, u32)>
pub fn submit_with_flags<T: OpCode + 'static>( &self, op: T, ) -> impl Future<Output = (BufResult<usize, T>, u32)>
Submit an operation to the runtime.
The difference between Runtime::submit
is this method will return
the flags
You only need this when authoring your own OpCode
.
Sourcepub 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
.
Sourcepub 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
.
Trait Implementations§
Source§impl AsyncExecutor for &Runtime
Available on crate feature criterion
only.
impl AsyncExecutor for &Runtime
criterion
only.Source§impl AsyncExecutor for Runtime
Available on crate feature criterion
only.
impl AsyncExecutor for Runtime
criterion
only.Auto Trait Implementations§
impl !Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl !Send for Runtime
impl !Sync for Runtime
impl Unpin for Runtime
impl !UnwindSafe 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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