11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Test that calling worker.terminate() if kHandler is null should return an 71cb0ef41Sopenharmony_ci// empty promise that resolves to undefined, even when a callback is passed 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst worker = new Worker(` 101cb0ef41Sopenharmony_ciconst { parentPort } = require('worker_threads'); 111cb0ef41Sopenharmony_ciparentPort.postMessage({ hello: 'world' }); 121cb0ef41Sopenharmony_ci`, { eval: true }); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciprocess.once('beforeExit', common.mustCall(() => worker.ref())); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciworker.on('exit', common.mustCall(() => { 171cb0ef41Sopenharmony_ci worker.terminate().then((res) => assert.strictEqual(res, undefined)); 181cb0ef41Sopenharmony_ci worker.terminate(() => null).then( 191cb0ef41Sopenharmony_ci (res) => assert.strictEqual(res, undefined) 201cb0ef41Sopenharmony_ci ); 211cb0ef41Sopenharmony_ci})); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciworker.unref(); 24