Return to just TaskId, still polling

This commit is contained in:
Exotik850 committed 2023-12-12 13:02:35 -06:00
1 parent 69ca1fd8a7
commit fdce7bbe5a
8 files changed
+26 -34

No files matched your search

+3 -3
View File
@@ -63,15 +63,15 @@ use std::future::Future;
/// }
/// })
/// ```
pub fn use_coroutine<M, G, F>(cx: &ScopeState, init: G) -> Option<&Coroutine<M>>
pub fn use_coroutine<M, G, F>(cx: &ScopeState, init: G) -> &Coroutine<M>
where
M: 'static,
G: FnOnce(UnboundedReceiver<M>) -> F,
F: Future<Output = ()> + 'static,
{
let (tx, rx) = futures_channel::mpsc::unbounded();
let task = cx.push_future(init(rx))?;
Some(cx.use_hook(|| cx.provide_context(Coroutine { tx, task })))
let task = cx.push_future(init(rx));
cx.use_hook(|| cx.provide_context(Coroutine { tx, task }))
}
/// Get a handle to a coroutine higher in the tree
+5 -6
View File
@@ -99,9 +99,8 @@ where
// Create the new future
let return_value = future(dependencies.out());
if let Some(task) = return_value.apply(state.cleanup.clone(), cx) {
state.task.set(Some(task));
}
let task = return_value.apply(state.cleanup.clone(), cx);
state.task.set(Some(task));
}
}
@@ -109,14 +108,14 @@ type UseEffectCleanup = Rc<RefCell<Option<Box<dyn FnOnce()>>>>;
/// Something that can be returned from a `use_effect` hook.
pub trait UseEffectReturn<T> {
fn apply(self, oncleanup: UseEffectCleanup, cx: &ScopeState) -> Option<TaskId>;
fn apply(self, oncleanup: UseEffectCleanup, cx: &ScopeState) -> TaskId;
}
impl<T> UseEffectReturn<()> for T
where
T: Future<Output = ()> + 'static,
{
fn apply(self, _: UseEffectCleanup, cx: &ScopeState) -> Option<TaskId> {
fn apply(self, _: UseEffectCleanup, cx: &ScopeState) -> TaskId {
cx.push_future(self)
}
}
@@ -128,7 +127,7 @@ where
T: Future<Output = F> + 'static,
F: FnOnce() + 'static,
{
fn apply(self, oncleanup: UseEffectCleanup, cx: &ScopeState) -> Option<TaskId> {
fn apply(self, oncleanup: UseEffectCleanup, cx: &ScopeState) -> TaskId {
cx.push_future(async move {
let cleanup = self.await;
*oncleanup.borrow_mut() = Some(Box::new(cleanup) as Box<dyn FnOnce()>);
+2 -2
View File
@@ -49,10 +49,10 @@ where
let val = val.clone();
let task = state.task.clone();
state.task.set(cx.push_future(async move {
state.task.set(Some(cx.push_future(async move {
val.set(Some(fut.await));
task.take();
}));
})));
// Mark that we don't need to regenerate
state.needs_regen.set(false);