move ScopeId methods to the runtime (#4723)
* move `ScopeId` methods to runtime methods * cargo check unused * wip... * wip... * fix consume context * fix test * guard hoisted * fix doc comment
This commit is contained in:
1 parent
c56bac04f4
commit
c29cef4ea3
40 files changed
+466
-697
No files matched your search
@@ -7,7 +7,6 @@ use crate::ScopeId;
|
||||
use futures_util::task::ArcWake;
|
||||
use slotmap::DefaultKey;
|
||||
use std::marker::PhantomData;
|
||||
use std::panic;
|
||||
use std::sync::Arc;
|
||||
use std::task::Waker;
|
||||
use std::{cell::Cell, future::Future};
|
||||
@@ -73,7 +72,6 @@ impl Task {
|
||||
false
|
||||
}
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Wake the task.
|
||||
@@ -84,13 +82,12 @@ impl Task {
|
||||
.sender
|
||||
.unbounded_send(SchedulerMsg::TaskNotified(self.id))
|
||||
})
|
||||
.unwrap_or_else(|e| panic!("{}", e))
|
||||
}
|
||||
|
||||
/// Poll the task immediately.
|
||||
#[track_caller]
|
||||
pub fn poll_now(&self) -> Poll<()> {
|
||||
Runtime::with(|rt| rt.handle_task_wakeup(*self)).unwrap_or_else(|e| panic!("{}", e))
|
||||
Runtime::with(|rt| rt.handle_task_wakeup(*self))
|
||||
}
|
||||
|
||||
/// Set the task as active or paused.
|
||||
@@ -106,7 +103,6 @@ impl Task {
|
||||
}
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|e| panic!("{}", e))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +213,7 @@ impl Runtime {
|
||||
/// Queue an effect to run after the next render
|
||||
pub(crate) fn queue_effect(&self, id: ScopeId, f: impl FnOnce() + 'static) {
|
||||
let effect = Box::new(f) as Box<dyn FnOnce() + 'static>;
|
||||
let Some(scope) = self.get_state(id) else {
|
||||
let Some(scope) = self.try_get_state(id) else {
|
||||
return;
|
||||
};
|
||||
let mut status = scope.status.borrow_mut();
|
||||
@@ -239,7 +235,8 @@ impl Runtime {
|
||||
) {
|
||||
// Add the effect to the queue of effects to run after the next render for the given scope
|
||||
let mut effects = self.pending_effects.borrow_mut();
|
||||
let scope_order = ScopeOrder::new(id.height(), id);
|
||||
let height = self.get_state(id).height();
|
||||
let scope_order = ScopeOrder::new(height, id);
|
||||
match effects.get(&scope_order) {
|
||||
Some(effects) => effects.push_back(f),
|
||||
None => {
|
||||
@@ -267,7 +264,7 @@ impl Runtime {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
// Ensure we are currently inside a `Runtime`.
|
||||
Runtime::current().unwrap_or_else(|e| panic!("{}", e));
|
||||
Runtime::current();
|
||||
}
|
||||
|
||||
let task = self.tasks.borrow().get(id.id).cloned();
|
||||
@@ -293,7 +290,6 @@ impl Runtime {
|
||||
if poll_result.is_ready() {
|
||||
// Remove it from the scope so we dont try to double drop it when the scope dropes
|
||||
self.get_state(task.scope)
|
||||
.unwrap()
|
||||
.spawned_tasks
|
||||
.borrow_mut()
|
||||
.remove(&id);
|
||||
@@ -325,7 +321,7 @@ impl Runtime {
|
||||
}
|
||||
|
||||
// Remove the task from pending work. We could reuse the slot before the task is polled and discarded so we need to remove it from pending work instead of filtering out dead tasks when we try to poll them
|
||||
if let Some(scope) = self.get_state(task.scope) {
|
||||
if let Some(scope) = self.try_get_state(task.scope) {
|
||||
let order = ScopeOrder::new(scope.height(), scope.id);
|
||||
if let Some(dirty_tasks) = self.dirty_tasks.borrow_mut().get(&order) {
|
||||
dirty_tasks.remove(id);
|
||||
|
||||
Reference in new issue
Block a user