1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 16:19:12 -05:00

fix(ext/node): add stub for AsyncResource#asyncId() (#23372)

Ref https://github.com/denoland/deno/issues/23263
This commit is contained in:
Divy Srivastava 2024-04-15 18:24:42 +05:30 committed by GitHub
parent 1835b4f061
commit f36a8951a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View file

@ -10,6 +10,7 @@
import { core } from "ext:core/mod.js"; import { core } from "ext:core/mod.js";
import { op_node_is_promise_rejected } from "ext:core/ops"; import { op_node_is_promise_rejected } from "ext:core/ops";
import { validateFunction } from "ext:deno_node/internal/validators.mjs"; import { validateFunction } from "ext:deno_node/internal/validators.mjs";
import { newAsyncId } from "ext:deno_node/internal/async_hooks.ts";
function assert(cond: boolean) { function assert(cond: boolean) {
if (!cond) throw new Error("Assertion failed"); if (!cond) throw new Error("Assertion failed");
@ -180,9 +181,16 @@ class AsyncContextFrame {
export class AsyncResource { export class AsyncResource {
frame: AsyncContextFrame; frame: AsyncContextFrame;
type: string; type: string;
#asyncId: number;
constructor(type: string) { constructor(type: string) {
this.type = type; this.type = type;
this.frame = AsyncContextFrame.current(); this.frame = AsyncContextFrame.current();
this.#asyncId = newAsyncId();
}
asyncId() {
return this.#asyncId;
} }
runInAsyncScope( runInAsyncScope(

View file

@ -125,3 +125,8 @@ Deno.test(async function bind() {
assertEquals(await deferred.promise, null); assertEquals(await deferred.promise, null);
}); });
Deno.test(function asyncResourceStub() {
const resource = new AsyncResource("dbquery");
assert(typeof resource.asyncId() === "number");
});