diff --git a/worker/src/send.rs b/worker/src/send.rs index 074f354b..ed0025fb 100644 --- a/worker/src/send.rs +++ b/worker/src/send.rs @@ -41,6 +41,29 @@ impl Future for SendFuture { } } +/// Trait for SendFuture. Implemented for any type that implements Future. +/// +/// ```rust +/// let fut = JsFuture::from(promise).into_send(); +/// fut.await +/// ``` +pub trait IntoSendFuture { + type Output; + fn into_send(self) -> SendFuture + where + Self: Sized; +} + +impl IntoSendFuture for F +where + F: Future, +{ + type Output = T; + fn into_send(self) -> SendFuture { + SendFuture::new(self) + } +} + /// Wrap any type to make it `Send`. /// /// ```rust