Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks: add an InactiveAsyncContextFrame class #54510

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/internal/async_context_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {

let enabled_;

class ActiveAsyncContextFrame {
class ActiveAsyncContextFrame extends Map {
static get enabled() {
return true;
}
Expand Down Expand Up @@ -50,12 +50,7 @@ function checkEnabled() {
return enabled;
}

class AsyncContextFrame extends Map {
constructor(store, data) {
super(AsyncContextFrame.current());
this.set(store, data);
}

class InactiveAsyncContextFrame extends Map {
static get enabled() {
enabled_ ??= checkEnabled();
return enabled_;
Expand All @@ -65,6 +60,13 @@ class AsyncContextFrame extends Map {
static set(frame) {}
static exchange(frame) {}
static disable(store) {}
}

class AsyncContextFrame extends InactiveAsyncContextFrame {
constructor(store, data) {
super(AsyncContextFrame.current());
this.set(store, data);
}

disable(store) {
this.delete(store);
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-async-context-frame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { opendir } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { describe, it } from 'node:test';
import { sep } from 'node:path';
import { strictEqual } from 'node:assert';

const python = process.env.PYTHON || (isWindows ? 'python' : 'python3');

Expand Down Expand Up @@ -53,7 +54,8 @@ describe('AsyncContextFrame', {
stdio: ['ignore', 'ignore', 'inherit'],
});

await once(proc, 'exit');
const [code] = await once(proc, 'exit');
strictEqual(code, 0, `Test ${test} failed with exit code ${code}`);
});
}
});
Loading