1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { isMainThread, parentPort, Worker } = require('worker_threads'); 5 6// This test makes sure that we manipulate the references of 7// `parentPort` correctly so that any worker threads will 8// automatically exit when there are no any other references. 9{ 10 if (isMainThread) { 11 const worker = new Worker(__filename); 12 13 worker.on('exit', common.mustCall((code) => { 14 assert.strictEqual(code, 0); 15 }), 1); 16 17 worker.on('online', common.mustCall()); 18 } else { 19 const messageCallback = () => {}; 20 parentPort.on('message', messageCallback); 21 // The thread won't exit if we don't make the 'message' listener off. 22 parentPort.off('message', messageCallback); 23 } 24} 25