mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Signed-off-by: avivkeller <me@aviv.sh> PR-URL: https://github.com/nodejs/node/pull/65323 Refs: https://github.com/nodejs/node/pull/64894 Refs: https://github.com/nodejs/node/issues/43583 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
29 lines
807 B
JavaScript
29 lines
807 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const assert = require('assert');
|
|
|
|
{
|
|
// Both are no-ops on a worker whose script could not be loaded.
|
|
const worker = new Worker(fixtures.fileURL('web-worker', 'nonexistent.js').href);
|
|
worker.addEventListener('error', common.mustCall());
|
|
process.unref(worker);
|
|
process.ref(worker);
|
|
}
|
|
|
|
const worker = new Worker(fixtures.fileURL('web-worker', 'echo.js').href);
|
|
|
|
worker.addEventListener('error', common.mustNotCall('worker failed'));
|
|
worker.addEventListener('message', common.mustCall(({ data }) => {
|
|
assert.strictEqual(data, 'hello');
|
|
worker.terminate();
|
|
}));
|
|
|
|
process.once('beforeExit', common.mustCall(() => {
|
|
process.ref(worker);
|
|
worker.postMessage('hello');
|
|
}));
|
|
|
|
process.unref(worker);
|