mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 17:57:53 +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>
18 lines
564 B
JavaScript
18 lines
564 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 cwdName = path.relative('../', '.');
|
|
const relativePath = path.relative('.', __filename);
|
|
const w = new Worker(path.join('..', cwdName, relativePath));
|
|
w.on('message', common.mustCall((message) => {
|
|
assert.strictEqual(message, 'Hello, world!');
|
|
}));
|
|
} else {
|
|
parentPort.postMessage('Hello, world!');
|
|
}
|