diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-11-25 19:49:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-25 19:49:09 +0100 |
commit | f3c0f0565bbf43b4cc31979b05e729d4f4a1538f (patch) | |
tree | 6554dfdecd89e076166531b91824d6750d5b76e0 /core/ops_metrics.rs | |
parent | 2853e3760471560c1812b46007e1a525966b1365 (diff) |
feat(core): Add ability to "ref" and "unref" pending ops (#12889)
This commit adds an ability to "ref" or "unref" pending ops.
Up to this point Deno had a notion of "async ops" and "unref async ops";
the former keep event loop alive, while the latter do not block event loop
from finishing. It was not possible to change between op types after
dispatching, one had to decide which type to use before dispatch.
Instead of storing ops in two separate "FuturesUnordered" collections,
now ops are stored in a single collection, with supplemental "HashSet"
storing ids of promises that were "unrefed".
Two APIs were added to "Deno.core":
"Deno.core.refOp(promiseId)" which allows to mark promise id
to be "refed" and keep event loop alive (the default behavior)
"Deno.core.unrefOp(promiseId)" which allows to mark promise
id as "unrefed" which won't block event loop from exiting
Diffstat (limited to 'core/ops_metrics.rs')
-rw-r--r-- | core/ops_metrics.rs | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/core/ops_metrics.rs b/core/ops_metrics.rs index 5c40a47ca..f2e9bc255 100644 --- a/core/ops_metrics.rs +++ b/core/ops_metrics.rs @@ -11,10 +11,12 @@ pub struct OpMetrics { pub ops_dispatched: u64, pub ops_dispatched_sync: u64, pub ops_dispatched_async: u64, + // TODO(bartlomieju): this field is never updated pub ops_dispatched_async_unref: u64, pub ops_completed: u64, pub ops_completed_sync: u64, pub ops_completed_async: u64, + // TODO(bartlomieju): this field is never updated pub ops_completed_async_unref: u64, pub bytes_sent_control: u64, pub bytes_sent_data: u64, @@ -84,16 +86,4 @@ impl OpsTracker { metrics.ops_completed += 1; metrics.ops_completed_async += 1; } - - pub fn track_unref(&self, id: OpId) { - let metrics = &mut self.metrics_mut(id); - metrics.ops_dispatched += 1; - metrics.ops_dispatched_async_unref += 1; - } - - pub fn track_unref_completed(&self, id: OpId) { - let metrics = &mut self.metrics_mut(id); - metrics.ops_completed += 1; - metrics.ops_completed_async_unref += 1; - } } |