feat: allow 'static futures to be spawned from handlers

This commit is contained in:
Jonathan Kelley committed 2023-02-06 00:54:08 -08:00
1 parent d0fb05385a
commit 9ebafc46bb
5 files changed
+38 -9

No files matched your search

+4 -3
View File
@@ -7,7 +7,7 @@ use crate::{
innerlude::{ErrorBoundary, Scheduler, SchedulerMsg},
lazynodes::LazyNodes,
nodes::{ComponentReturn, IntoAttributeValue, IntoDynNode, RenderReturn},
AnyValue, Attribute, AttributeValue, Element, Event, Properties, TaskId,
AnyValue, Attribute, AttributeValue, Element, Event, EventReturn, Properties, TaskId,
};
use bumpalo::{boxed::Box as BumpBox, Bump};
use bumpslab::{BumpSlab, Slot};
@@ -581,9 +581,9 @@ impl<'src> ScopeState {
/// Create a new [`AttributeValue`] with the listener variant from a callback
///
/// The callback must be confined to the lifetime of the ScopeState
pub fn listener<T: 'static>(
pub fn listener<T: 'static, P, E: EventReturn<P>>(
&'src self,
mut callback: impl FnMut(Event<T>) + 'src,
mut callback: impl FnMut(Event<T>) -> E + 'src,
) -> AttributeValue<'src> {
// safety: there's no other way to create a dynamicly-dispatched bump box other than alloc + from-raw
// This is the suggested way to build a bumpbox
@@ -596,6 +596,7 @@ impl<'src> ScopeState {
propagates: event.propagates,
data,
})
.spawn(self);
}
}))
};