summaryrefslogtreecommitdiff
path: root/core/ops.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-07 23:50:14 +0200
committerGitHub <noreply@github.com>2023-06-07 23:50:14 +0200
commit19f82b0eaa14f0df58fdfc685e60c8560582c5a4 (patch)
tree0269a3fb0e70fb37856b5d4a2b5a1e737be9feb7 /core/ops.rs
parent7e91f74d2b00cdc64042ba66e45d912fa2d9b647 (diff)
refactor(core): use JoinSet instead of FuturesUnordered (#19378)
This commit migrates "deno_core" from using "FuturesUnordered" to "tokio::task::JoinSet". This makes every op to be a separate Tokio task and should unlock better utilization of kqueue/epoll. There were two quirks added to this PR: - because of the fact that "JoinSet" immediately polls spawn tasks, op sanitizers can give false positives in some cases, this was alleviated by polling event loop once before running a test with "deno test", which gives canceled ops an opportunity to settle - "JsRuntimeState::waker" was moved to "OpState::waker" so that FFI API can still use threadsafe functions - without this change the registered wakers were wrong as they would not wake up the whole "JsRuntime" but the task associated with an op --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
Diffstat (limited to 'core/ops.rs')
-rw-r--r--core/ops.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/core/ops.rs b/core/ops.rs
index 5f1bf67ef..b766eb60d 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -10,6 +10,7 @@ use crate::OpDecl;
use crate::OpsTracker;
use anyhow::Error;
use futures::future::MaybeDone;
+use futures::task::AtomicWaker;
use futures::Future;
use futures::FutureExt;
use pin_project::pin_project;
@@ -21,6 +22,7 @@ use std::pin::Pin;
use std::ptr::NonNull;
use std::rc::Rc;
use std::rc::Weak;
+use std::sync::Arc;
use v8::fast_api::CFunctionInfo;
use v8::fast_api::CTypeInfo;
@@ -184,6 +186,7 @@ pub struct OpState {
pub tracker: OpsTracker,
pub last_fast_op_error: Option<AnyError>,
pub(crate) gotham_state: GothamState,
+ pub waker: Arc<AtomicWaker>,
}
impl OpState {
@@ -194,6 +197,7 @@ impl OpState {
gotham_state: Default::default(),
last_fast_op_error: None,
tracker: OpsTracker::new(ops_count),
+ waker: Arc::new(AtomicWaker::new()),
}
}