actually set task

This commit is contained in:
Jonathan Kelley 2024-01-15 17:37:50 -08:00
parent 1332b82dc8
commit ee5020c41f
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
3 changed files with 6 additions and 5 deletions

View file

@ -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)
}

View file

@ -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);
}
}

View file

@ -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) {
with_runtime(|rt| {
// Drop all spawned tasks
with_runtime(|rt| {
for id in self.spawned_tasks.borrow().iter() {
rt.remove(*id);
rt.remove_task(*id);
}
})
.expect("Runtime to exist")