Skip to main content

BlockingAsyncProducer

Struct BlockingAsyncProducer 

Source
pub struct BlockingAsyncProducer<F, Fut>
where F: Fn() -> Fut, Fut: Future<Output = Report>,
{ /* private fields */ }
Expand description

Adapter that wraps an async fn returning a Report and implements dev_report::Producer by calling tokio::runtime::Handle::current().block_on(...).

MUST be invoked from a sync context that is not itself running inside a current_thread runtime. Calling block_on from inside an async runtime would deadlock; if you need that, use AsyncProducer directly without going through Producer.

§Example

use dev_async::{run_with_timeout, BlockingAsyncProducer};
use dev_report::{Producer, Report};
use std::time::Duration;

fn build_report() -> impl std::future::Future<Output = Report> {
    async {
        let check = run_with_timeout("op", Duration::from_millis(50), async {}).await;
        let mut r = Report::new("crate", "0.1.0").with_producer("dev-async");
        r.push(check);
        r.finish();
        r
    }
}

// From a sync test or main:
// let rt = tokio::runtime::Runtime::new().unwrap();
// let handle = rt.handle().clone();
// let producer = BlockingAsyncProducer::new(handle, build_report);
// let report = producer.produce();

Implementations§

Source§

impl<F, Fut> BlockingAsyncProducer<F, Fut>
where F: Fn() -> Fut, Fut: Future<Output = Report>,

Source

pub fn new(handle: Handle, factory: F) -> Self

Build a new adapter bound to handle.

factory is invoked once per produce() call and must return a fresh future each time.

Trait Implementations§

Source§

impl<F, Fut> Producer for BlockingAsyncProducer<F, Fut>
where F: Fn() -> Fut, Fut: Future<Output = Report>,

Source§

fn produce(&self) -> Report

Run the producer and return a finalized report. Read more

Auto Trait Implementations§

§

impl<F, Fut> Freeze for BlockingAsyncProducer<F, Fut>
where F: Freeze,

§

impl<F, Fut> RefUnwindSafe for BlockingAsyncProducer<F, Fut>
where F: RefUnwindSafe,

§

impl<F, Fut> Send for BlockingAsyncProducer<F, Fut>
where F: Send,

§

impl<F, Fut> Sync for BlockingAsyncProducer<F, Fut>
where F: Sync,

§

impl<F, Fut> Unpin for BlockingAsyncProducer<F, Fut>
where F: Unpin,

§

impl<F, Fut> UnsafeUnpin for BlockingAsyncProducer<F, Fut>
where F: UnsafeUnpin,

§

impl<F, Fut> UnwindSafe for BlockingAsyncProducer<F, Fut>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.