diff options
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/01_async_context.js | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/runtime/js/01_async_context.js b/runtime/js/01_async_context.js deleted file mode 100644 index 9c0236fbe..000000000 --- a/runtime/js/01_async_context.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -import { primordials } from "ext:core/mod.js"; -import { op_get_extras_binding_object } from "ext:core/ops"; - -const { - SafeWeakMap, -} = primordials; - -const { - getContinuationPreservedEmbedderData, - setContinuationPreservedEmbedderData, -} = op_get_extras_binding_object(); - -let counter = 0; - -export const getAsyncContext = getContinuationPreservedEmbedderData; -export const setAsyncContext = setContinuationPreservedEmbedderData; - -export class AsyncVariable { - #id = counter++; - #data = new SafeWeakMap(); - - enter(value) { - const previousContextMapping = getAsyncContext(); - const entry = { id: this.#id }; - const asyncContextMapping = { - __proto__: null, - ...previousContextMapping, - [this.#id]: entry, - }; - this.#data.set(entry, value); - setAsyncContext(asyncContextMapping); - return previousContextMapping; - } - - get() { - const current = getAsyncContext(); - const entry = current?.[this.#id]; - if (entry) { - return this.#data.get(entry); - } - return undefined; - } -} |