feat: allow 'static futures to be spawned from handlers
This commit is contained in:
1 parent
d0fb05385a
commit
9ebafc46bb
5 files changed
+38
-9
No files matched your search
@@ -3,6 +3,10 @@ use std::{
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use futures_util::Future;
|
||||
|
||||
use crate::ScopeState;
|
||||
|
||||
/// A wrapper around some generic data that handles the event's state
|
||||
///
|
||||
///
|
||||
@@ -106,6 +110,23 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub trait EventReturn<P>: Sized {
|
||||
fn spawn(self, _cx: &ScopeState) {}
|
||||
}
|
||||
|
||||
impl EventReturn<()> for () {}
|
||||
|
||||
pub struct AsyncMarker;
|
||||
impl<T> EventReturn<AsyncMarker> for T
|
||||
where
|
||||
T: Future<Output = ()> + 'static,
|
||||
{
|
||||
fn spawn(self, cx: &ScopeState) {
|
||||
cx.spawn(self);
|
||||
}
|
||||
}
|
||||
|
||||
/// The callback type generated by the `rsx!` macro when an `on` field is specified for components.
|
||||
///
|
||||
/// This makes it possible to pass `move |evt| {}` style closures into components as property fields.
|
||||
|
||||
Reference in new issue
Block a user