-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-async-local-storage-gc.js
More file actions
34 lines (29 loc) · 1001 Bytes
/
test-async-local-storage-gc.js
File metadata and controls
34 lines (29 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Flags: --async-context-frame --expose-gc --expose-internals
'use strict';
const common = require('../common');
const { gcUntil } = require('../common/gc');
const { AsyncLocalStorage } = require('async_hooks');
const AsyncContextFrame = require('internal/async_context_frame');
// To be compatible with `test-without-async-context-frame.mjs`.
if (!AsyncContextFrame.enabled) {
common.skip('AsyncContextFrame is not enabled');
}
// Verify that the AsyncLocalStorage object can be garbage collected even without
// `asyncLocalStorage.disable()` being called, when `--async-context-frame` is enabled.
let weakRef = null;
{
const alsValue = {};
let als = new AsyncLocalStorage();
als.run(alsValue, () => {
setInterval(() => {
/**
* Empty interval to keep the als value alive.
*/
}, 1000).unref();
});
weakRef = new WeakRef(als);
als = null;
}
gcUntil('AsyncLocalStorage object can be garbage collected', () => {
return weakRef.deref() === undefined;
});