Skip to content

worker.onmessage is not called #26856

Description

@surma
// main.mjs
import {Worker} from 'worker_threads';

const worker = new Worker("./worker.mjs");
worker.onmessage = ev => console.log("onmessage", ev);
worker.on("message", ev => console.log("EventEmitter", ev));
worker.postMessage("from main to worker")
// worker.mjs
import {parentPort} from 'worker_threads';

parentPort.onmessage = ev => console.log(ev);
parentPort.postMessage("from worker to main");

If you run the main.mjs file above, you’ll see only the EventEmitter handler is called, but not the one registered via onmessage.

I think for consistence (as well as the fake MessageEvent handling introduced in #26082), it is desirable to add support for onmessage on Worker.

cc @addaleax

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions