Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addListener doesn't work inside the worker #8

Open
notpushkin opened this issue Aug 13, 2014 · 0 comments
Open

addListener doesn't work inside the worker #8

notpushkin opened this issue Aug 13, 2014 · 0 comments

Comments

@notpushkin
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant