Struct compio_runtime::Runtime
source · 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_current() -> Option<Self>
pub fn try_current() -> Option<Self>
Get the current running Runtime
.
sourcepub fn enter(&self) -> EnterGuard<'_>
pub fn enter(&self) -> EnterGuard<'_>
Enter the runtime context. This runtime will be set as the current
one.
Panics
When calling Runtime::enter
multiple times, the returned guards
must be dropped in the reverse order that they were acquired.
Failure to do so will result in a panic and possible memory leaks.
Do not do the following, this shows a scenario that will result in a panic and possible memory leak.
use compio_runtime::Runtime;
let rt1 = Runtime::new().unwrap();
let rt2 = Runtime::new().unwrap();
let enter1 = rt1.enter();
let enter2 = rt2.enter();
drop(enter1);
drop(enter2);
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) -> Task<F::Output> ⓘ
pub fn spawn<F: Future + 'static>(&self, future: F) -> Task<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.
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.