Skip to content

worker.onmessage is not called #26856

Closed
Closed
@surma

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 that request new features to be added to Node.js.staleworkerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions