From b3fbbba7113a3e53d49a171cca6a5f6ed72243b8 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 4 Aug 2023 17:25:40 -0700 Subject: [PATCH] fix signals in futures --- examples/clock.rs | 12 ++++++------ packages/core/src/scheduler/wait.rs | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/clock.rs b/examples/clock.rs index b0ea29b4..5c4bc4f2 100644 --- a/examples/clock.rs +++ b/examples/clock.rs @@ -33,12 +33,12 @@ struct ChildProps { fn Child(cx: Scope) -> Element { let count = cx.props.count; - // use_future!(cx, || async move { - // loop { - // tokio::time::sleep(std::time::Duration::from_secs(count.value())).await; - // *count.write() += 1; - // } - // }); + use_future!(cx, || async move { + loop { + tokio::time::sleep(std::time::Duration::from_secs(count.value())).await; + *count.write() += 1; + } + }); render! { div { diff --git a/packages/core/src/scheduler/wait.rs b/packages/core/src/scheduler/wait.rs index a04bf273..47180c24 100644 --- a/packages/core/src/scheduler/wait.rs +++ b/packages/core/src/scheduler/wait.rs @@ -17,6 +17,9 @@ impl VirtualDom { let mut cx = Context::from_waker(&task.waker); + // update the scope stack + self.runtime.scope_stack.borrow_mut().push(task.scope); + // If the task completes... if task.task.borrow_mut().as_mut().poll(&mut cx).is_ready() { // Remove it from the scope so we dont try to double drop it when the scope dropes @@ -26,5 +29,8 @@ impl VirtualDom { // Remove it from the scheduler tasks.try_remove(id.0); } + + // Remove the scope from the stack + self.runtime.scope_stack.borrow_mut().pop(); } }