mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
05bb4a716b
PR-URL: https://github.com/nodejs/node/pull/53239 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
32 lines
704 B
JavaScript
32 lines
704 B
JavaScript
import { strictEqual } from 'assert'
|
|
|
|
function setup() {
|
|
const obj = { foo: 'bar' }
|
|
process.finalization.registerBeforeExit(obj, shutdown)
|
|
}
|
|
|
|
let shutdownCalled = false
|
|
let timeoutFinished = false
|
|
|
|
function shutdown(obj, event) {
|
|
shutdownCalled = true
|
|
if (event === 'beforeExit') {
|
|
setTimeout(function () {
|
|
timeoutFinished = true
|
|
strictEqual(obj.foo, 'bar')
|
|
process.finalization.unregister(obj)
|
|
}, 100)
|
|
process.on('beforeExit', function () {
|
|
strictEqual(timeoutFinished, true)
|
|
})
|
|
} else {
|
|
throw new Error(`different event, expected beforeExit but got ${event}`)
|
|
}
|
|
}
|
|
|
|
setup()
|
|
|
|
process.on('exit', function () {
|
|
strictEqual(shutdownCalled, true)
|
|
})
|