pub enum NodeRuntime {
Owned(Arc<OwnedRuntime>),
Borrowed(Handle),
}Expand description
The runtime a node’s background tasks run on.
Variants§
Owned(Arc<OwnedRuntime>)
A runtime this node built and owns; it shuts down when the last handle drops.
Borrowed(Handle)
A runtime the caller already had running.
Implementations§
Source§impl NodeRuntime
impl NodeRuntime
Sourcepub fn acquire() -> Result<Self>
pub fn acquire() -> Result<Self>
The runtime to use here: the caller’s if one is running, otherwise a freshly built one.
§Errors
NodeError::Runtime when no runtime is running and one cannot be
built (which in practice means the process cannot start threads).
Sourcepub fn owned() -> Result<Self>
pub fn owned() -> Result<Self>
A freshly built runtime, ignoring any the caller has.
§Errors
NodeError::Runtime when the runtime cannot be built.
Sourcepub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
Spawns a background task.
Sourcepub fn can_block(&self) -> bool
pub fn can_block(&self) -> bool
Whether a blocking call from this thread is safe.
False exactly in the deadlock case: the calling thread is the single worker of a current-thread runtime.
Sourcepub fn block_on<F: Future>(
&self,
method: &'static str,
alternative: &'static str,
future: F,
) -> Result<F::Output>
pub fn block_on<F: Future>( &self, method: &'static str, alternative: &'static str, future: F, ) -> Result<F::Output>
Runs future to completion, blocking the calling thread.
§Errors
NodeError::BlockingInAsync when the calling thread is a
current-thread runtime’s only worker; method and alternative name
what was called and what to call instead.