[][src]Trait tokio_util::context::RuntimeExt

pub trait RuntimeExt {
    pub 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;
; }
This is supported on crate feature rt only.

Trait extension that simplifies bundling a Handle with a Future.

Required methods

pub 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]

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 }),
);
Loading content...

Implementations on Foreign Types

impl RuntimeExt for Runtime[src]

Loading content...

Implementors

Loading content...