diff options
Diffstat (limited to 'core/01_core.js')
-rw-r--r-- | core/01_core.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/core/01_core.js b/core/01_core.js index 50d4537f0..b6c72e5d2 100644 --- a/core/01_core.js +++ b/core/01_core.js @@ -29,7 +29,7 @@ } = window.__bootstrap.primordials; // Available on start due to bindings. - const { opcallSync, opcallAsync } = window.Deno.core; + const { opcallSync, opcallAsync, refOp_, unrefOp_ } = window.Deno.core; let opsCache = {}; const errorMap = {}; @@ -99,6 +99,17 @@ return promise; } + function hasPromise(promiseId) { + // Check if out of ring bounds, fallback to map + const outOfBounds = promiseId < nextPromiseId - RING_SIZE; + if (outOfBounds) { + return MapPrototypeHas(promiseMap, promiseId); + } + // Otherwise check it in ring + const idx = promiseId % RING_SIZE; + return promiseRing[idx] != NO_PROMISE; + } + function ops() { return opsCache; } @@ -172,6 +183,20 @@ return unwrapOpResult(opcallSync(opsCache[opName], arg1, arg2)); } + function refOp(promiseId) { + if (!hasPromise(promiseId)) { + return; + } + refOp_(promiseId); + } + + function unrefOp(promiseId) { + if (!hasPromise(promiseId)) { + return; + } + unrefOp_(promiseId); + } + function resources() { return ObjectFromEntries(opSync("op_resources")); } @@ -252,6 +277,8 @@ enableOpCallTracing, isOpCallTracingEnabled, opCallTraces, + refOp, + unrefOp, }); ObjectAssign(globalThis.__bootstrap, { core }); |