Sha256: f43098955f6e1f3de254c24969810d844211c52d9ae0e1cebd8137567c78e5b5

Contents?: true

Size: 972 Bytes

Versions: 4

Compression:

Stored size: 972 Bytes

Contents

use core::any::Any;
use core::pin::Pin;
use std::boxed::Box;
use std::panic::{catch_unwind, AssertUnwindSafe, UnwindSafe};

use futures_core::future::Future;
use futures_core::task::{Context, Poll};
use pin_project_lite::pin_project;

pin_project! {
    /// Future for the [`catch_unwind`](super::FutureExt::catch_unwind) method.
    #[derive(Debug)]
    #[must_use = "futures do nothing unless you `.await` or poll them"]
    pub struct CatchUnwind<Fut> {
        #[pin]
        future: Fut,
    }
}

impl<Fut> CatchUnwind<Fut>
where
    Fut: Future + UnwindSafe,
{
    pub(super) fn new(future: Fut) -> Self {
        Self { future }
    }
}

impl<Fut> Future for CatchUnwind<Fut>
where
    Fut: Future + UnwindSafe,
{
    type Output = Result<Fut::Output, Box<dyn Any + Send>>;

    fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        let f = self.project().future;
        catch_unwind(AssertUnwindSafe(|| f.poll(cx)))?.map(Ok)
    }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/futures-util-0.3.31/src/future/future/catch_unwind.rs
wasmtime-28.0.0 ./ext/cargo-vendor/futures-util-0.3.31/src/future/future/catch_unwind.rs
wasmtime-27.0.0 ./ext/cargo-vendor/futures-util-0.3.31/src/future/future/catch_unwind.rs
wasmtime-26.0.0 ./ext/cargo-vendor/futures-util-0.3.31/src/future/future/catch_unwind.rs