mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00

PR-URL: https://github.com/nodejs/node/pull/56712 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
28 lines
638 B
JavaScript
28 lines
638 B
JavaScript
'use strict';
|
|
// Flags: --expose_gc
|
|
|
|
// This test ensures that userland-only AsyncResources cause a destroy event to
|
|
// be emitted when they get gced.
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const async_hooks = require('async_hooks');
|
|
|
|
const destroyedIds = new Set();
|
|
async_hooks.createHook({
|
|
destroy: common.mustCallAtLeast((asyncId) => {
|
|
destroyedIds.add(asyncId);
|
|
}, 1)
|
|
}).enable();
|
|
|
|
let asyncId = null;
|
|
{
|
|
const res = new async_hooks.AsyncResource('foobar');
|
|
asyncId = res.asyncId();
|
|
}
|
|
|
|
setImmediate(() => {
|
|
globalThis.gc();
|
|
setImmediate(() => assert.ok(destroyedIds.has(asyncId)));
|
|
});
|