mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:13:21 +00:00

In cases where libraries create AsyncResources which may be emitting more events depending on usage, the only way to ensure that destroy is called properly is by calling it when the resource gets garbage collected. Fixes: https://github.com/nodejs/node/issues/16153 PR-URL: https://github.com/nodejs/node/pull/16998 Fixes: https://github.com/nodejs/node/issues/16153 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
25 lines
518 B
JavaScript
25 lines
518 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 async_hooks = require('async_hooks');
|
|
|
|
const hook = async_hooks.createHook({
|
|
destroy: common.mustCall(2) // 1 immediate + manual destroy
|
|
}).enable();
|
|
|
|
{
|
|
const res = new async_hooks.AsyncResource('foobar');
|
|
res.emitDestroy();
|
|
}
|
|
|
|
setImmediate(() => {
|
|
global.gc();
|
|
setImmediate(() => {
|
|
hook.disable();
|
|
});
|
|
});
|