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

Activity

  1. added
    workerIssues and PRs related to the worker_threads module and Worker API.
    on Mar 27, 2019
  2. GrosSacASac commented on Apr 1, 2019

    @GrosSacASac
    Contributor

    Thanks, we should also consider supporting .addEventListener and .removeEventListener as well.
    Web Worker in the browser support it.

  3. jasnell commented on Jun 26, 2020

    @jasnell
    Member

    Refs: #34057

  4. addaleax commented on Jun 26, 2020

    @addaleax
    Member

    To be clear, #34057 does this for MessagePort, not Worker. I’m not sure whether we really want this for the Worker class itself.

  5. jasnell commented on Jun 26, 2020

    @jasnell
    Member

    Yep, not really seeing much value in having Worker extend EventTarget right now.

  6. github-actions commented on Mar 8, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Mar 8, 2022
  8. moved this to Pending Triage in Node.js feature requestson Mar 8, 2022
  9. moved this from Pending Triage to Stale in Node.js feature requestson Mar 8, 2022
  10. moved this to Pending Triage in Node.js feature requestson Mar 8, 2022
  11. moved this from Pending Triage to Stale in Node.js feature requestson Mar 8, 2022
  12. github-actions commented on Apr 8, 2022

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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