summaryrefslogtreecommitdiff
path: root/core/lib.deno_core.d.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-11-25 19:49:09 +0100
committerGitHub <noreply@github.com>2021-11-25 19:49:09 +0100
commitf3c0f0565bbf43b4cc31979b05e729d4f4a1538f (patch)
tree6554dfdecd89e076166531b91824d6750d5b76e0 /core/lib.deno_core.d.ts
parent2853e3760471560c1812b46007e1a525966b1365 (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/lib.deno_core.d.ts')
-rw-r--r--core/lib.deno_core.d.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/core/lib.deno_core.d.ts b/core/lib.deno_core.d.ts
index f33f6164a..59b2df542 100644
--- a/core/lib.deno_core.d.ts
+++ b/core/lib.deno_core.d.ts
@@ -21,6 +21,14 @@ declare namespace Deno {
b?: any,
): Promise<any>;
+ /** Mark following promise as "ref", ie. event loop won't exit
+ * until all "ref" promises are resolved. All async ops are "ref" by default. */
+ function refOp(promiseId: number): void;
+
+ /** Mark following promise as "unref", ie. event loop will exit
+ * if there are only "unref" promises left. */
+ function unrefOps(promiseId: number): void;
+
/**
* Retrieve a list of all registered ops, in the form of a map that maps op
* name to internal numerical op id.