Skip to content

addListener doesn't work inside the worker #8

Description

@notpushkin

E. g. you can't do this:

// app.js
var NodeWorker = require("worker").Worker;
var worker = new NodeWorker("echo.worker.js");
worker.addListener("message", function (msg) { console.log(msg); });
worker.postMessage("world");
// echo.worker.js
var self = require("worker").worker;
self.addListener('message', function(e) { self.postMessage(e.data); }, false);

As you'll get this weird error:

ale@ale-Lenovo-B590 ~/Songbee/__sandbox__ $ node app.js 

undefined:1
undefined
^
SyntaxError: Unexpected token u
    at Object.parse (native)
    at Object.WorkerChild.handleMessage (__sandbox__/node_modules/worker/lib/worker.js:135:20)
    at Object.WorkerChild.handleData (__sandbox__/node_modules/worker/lib/worker.js:116:18)
    at Socket.<anonymous> (__sandbox__/node_modules/worker/lib/worker.js:63:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:736:14)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)

This seems a bit strange to me.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions