mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 20:06:58 +00:00

This commit adds support for relative paths in Worker. Paths are relative to the current working directory. PR-URL: https://github.com/nodejs/node/pull/21407 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
16 lines
463 B
JavaScript
16 lines
463 B
JavaScript
// Flags: --experimental-worker
|
|
'use strict';
|
|
const path = require('path');
|
|
const assert = require('assert');
|
|
const common = require('../common');
|
|
const { Worker, isMainThread, parentPort } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
const w = new Worker('./' + path.relative('.', __filename));
|
|
w.on('message', common.mustCall((message) => {
|
|
assert.strictEqual(message, 'Hello, world!');
|
|
}));
|
|
} else {
|
|
parentPort.postMessage('Hello, world!');
|
|
}
|