Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-worker-terminate-null-handler.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9db2e38b5c492070d276960469a6d953f4142a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

// Test that calling worker.terminate() if kHandler is null should return an
// empty promise that resolves to undefined, even when a callback is passed

const worker = new Worker(`
const { parentPort } = require('worker_threads');
parentPort.postMessage({ hello: 'world' });
`, { eval: true });

process.once('beforeExit', common.mustCall(() => worker.ref()));

worker.on('exit', common.mustCall(() => {
  worker.terminate().then((res) => assert.strictEqual(res, undefined));
  worker.terminate(() => null).then(
    (res) => assert.strictEqual(res, undefined)
  );
}));

worker.unref();