Skip to content

Commit

Permalink
Merge pull request #73 from himself65/async_hooks
Browse files Browse the repository at this point in the history
fix: missing apis in AsyncLocalStorage
  • Loading branch information
syrusakbary authored Apr 26, 2024
2 parents cf9b7ca + 08f1ae4 commit 806b6eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/builtins/internal_js_modules/node/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ export class AsyncLocalStorage {
const currentFrame = AsyncContextFrame.current();
return currentFrame.get(this.#key);
}
static bind(fn) {
return AsyncResource.bind(fn);
}
static snapshot() {
return AsyncLocalStorage.bind((
cb,
...args
) => cb(...args));
}
}
export function executionAsyncId() {
return 1;
Expand Down
11 changes: 11 additions & 0 deletions src/builtins/internal_js_modules/node/async_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ export class AsyncLocalStorage {
const currentFrame = AsyncContextFrame.current();
return currentFrame.get(this.#key);
}

static bind(fn: (...args: unknown[]) => unknown) {
return AsyncResource.bind(fn);
}

static snapshot() {
return AsyncLocalStorage.bind((
cb: (...args: unknown[]) => unknown,
...args: unknown[]
) => cb(...args));
}
}

export function executionAsyncId() {
Expand Down

0 comments on commit 806b6eb

Please sign in to comment.