Browse Source

actually set task

Jonathan Kelley 1 năm trước cách đây
mục cha
commit
ee5020c41f

+ 1 - 1
packages/core/src/scheduler/task.rs

@@ -89,7 +89,7 @@ impl Runtime {
     /// Drop the future with the given TaskId
     ///
     /// This does not abort the task, so you'll want to wrap it in an abort handle if that's important to you
-    pub fn remove(&self, id: Task) -> Option<LocalTask> {
+    pub(crate) fn remove_task(&self, id: Task) -> Option<LocalTask> {
         self.tasks.borrow_mut().try_remove(id.0)
     }
 

+ 2 - 0
packages/core/src/scheduler/wait.rs

@@ -21,6 +21,7 @@ impl VirtualDom {
         // update the scope stack
         self.runtime.scope_stack.borrow_mut().push(task.scope);
         self.runtime.rendering.set(false);
+        self.runtime.current_task.set(Some(id));
 
         // If the task completes...
         if task.task.borrow_mut().as_mut().poll(&mut cx).is_ready() {
@@ -35,5 +36,6 @@ impl VirtualDom {
         // Remove the scope from the stack
         self.runtime.scope_stack.borrow_mut().pop();
         self.runtime.rendering.set(true);
+        self.runtime.current_task.set(None);
     }
 }

+ 3 - 4
packages/core/src/scope_context.rs

@@ -8,7 +8,6 @@ use std::{
     any::Any,
     cell::{Cell, RefCell},
     future::Future,
-    rc::Rc,
     sync::Arc,
 };
 
@@ -250,7 +249,7 @@ impl ScopeContext {
     ///
     /// This drops the task immediately.
     pub fn remove_future(&self, id: Task) {
-        with_runtime(|rt| rt.remove(id)).expect("Runtime to exist");
+        with_runtime(|rt| rt.remove_task(id)).expect("Runtime to exist");
     }
 
     /// Mark this component as suspended and then return None
@@ -314,10 +313,10 @@ impl ScopeContext {
 
 impl Drop for ScopeContext {
     fn drop(&mut self) {
+        // Drop all spawned tasks
         with_runtime(|rt| {
-            // Drop all spawned tasks
             for id in self.spawned_tasks.borrow().iter() {
-                rt.remove(*id);
+                rt.remove_task(*id);
             }
         })
         .expect("Runtime to exist")