[−][src]Trait tokio_util::context::RuntimeExt
This is supported on crate feature
rt
only.Trait extension that simplifies bundling a Handle
with a Future
.
Required methods
fn wrap<F: Future>(&self, fut: F) -> TokioContext<'_, F>ⓘNotable traits for TokioContext<'_, F>
impl<F: Future, '_> Future for TokioContext<'_, F> type Output = F::Output;
Notable traits for TokioContext<'_, F>
impl<F: Future, '_> Future for TokioContext<'_, F> type Output = F::Output;
Convenience method that takes a Future and returns a TokioContext
.
Example: calling Tokio Runtime from a custom ThreadPool
use tokio_util::context::RuntimeExt; use tokio::time::{sleep, Duration}; let rt = tokio::runtime::Builder::new_multi_thread() .enable_all() .build() .unwrap(); let rt2 = tokio::runtime::Builder::new_multi_thread() .build() .unwrap(); let fut = sleep(Duration::from_millis(2)); rt.block_on( rt2 .wrap(async { sleep(Duration::from_millis(2)).await }), );
Implementations on Foreign Types
impl RuntimeExt for Runtime
[src]
fn wrap<F: Future>(&self, fut: F) -> TokioContext<'_, F>ⓘNotable traits for TokioContext<'_, F>
impl<F: Future, '_> Future for TokioContext<'_, F> type Output = F::Output;
[src]
Notable traits for TokioContext<'_, F>
impl<F: Future, '_> Future for TokioContext<'_, F> type Output = F::Output;