11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { isMainThread, parentPort, Worker } = require('worker_threads'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// This test makes sure that we manipulate the references of 71cb0ef41Sopenharmony_ci// `parentPort` correctly so that any worker threads will 81cb0ef41Sopenharmony_ci// automatically exit when there are no any other references. 91cb0ef41Sopenharmony_ci{ 101cb0ef41Sopenharmony_ci if (isMainThread) { 111cb0ef41Sopenharmony_ci const worker = new Worker(__filename); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci worker.on('exit', common.mustCall((code) => { 141cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 151cb0ef41Sopenharmony_ci }), 1); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci worker.on('online', common.mustCall()); 181cb0ef41Sopenharmony_ci } else { 191cb0ef41Sopenharmony_ci const messageCallback = () => {}; 201cb0ef41Sopenharmony_ci parentPort.on('message', messageCallback); 211cb0ef41Sopenharmony_ci // The thread won't exit if we don't make the 'message' listener off. 221cb0ef41Sopenharmony_ci parentPort.off('message', messageCallback); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci} 25