pub struct Runtime { /* private fields */ }Expand description
A configured Asupersync runtime.
Created via RuntimeBuilder. The runtime owns worker threads and a
three-lane priority scheduler. Clone is cheap (shared Arc).
§Example
ⓘ
let runtime = RuntimeBuilder::new().worker_threads(2).build()?;
// Run a future to completion on the current thread.
let result = runtime.block_on(async { 1 + 1 });
assert_eq!(result, 2);
// Spawn from outside async context via a handle.
let handle = runtime.handle().spawn(async { 42u32 });
let value = runtime.block_on(handle);
assert_eq!(value, 42);Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn with_config(config: RuntimeConfig) -> Result<Self, Error>
pub fn with_config(config: RuntimeConfig) -> Result<Self, Error>
Construct a runtime from the given configuration.
Sourcepub fn with_config_and_reactor(
config: RuntimeConfig,
reactor: Option<Arc<dyn Reactor>>,
) -> Result<Self, Error>
pub fn with_config_and_reactor( config: RuntimeConfig, reactor: Option<Arc<dyn Reactor>>, ) -> Result<Self, Error>
Construct a runtime from the given configuration and reactor.
Sourcepub fn handle(&self) -> RuntimeHandle
pub fn handle(&self) -> RuntimeHandle
Returns a handle that can spawn tasks from outside the runtime.
Sourcepub fn block_on<F: Future>(&self, future: F) -> F::Output
pub fn block_on<F: Future>(&self, future: F) -> F::Output
Run a future to completion on the current thread.
Sourcepub fn config(&self) -> &RuntimeConfig
pub fn config(&self) -> &RuntimeConfig
Returns a reference to the runtime configuration.
Sourcepub fn is_quiescent(&self) -> bool
pub fn is_quiescent(&self) -> bool
Returns true if the runtime is quiescent (no live tasks or I/O).
Sourcepub fn spawn_blocking<F>(&self, f: F) -> Option<BlockingTaskHandle>
pub fn spawn_blocking<F>(&self, f: F) -> Option<BlockingTaskHandle>
Sourcepub fn blocking_handle(&self) -> Option<BlockingPoolHandle>
pub fn blocking_handle(&self) -> Option<BlockingPoolHandle>
Returns a handle to the blocking pool, if configured.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).