Code Monkey home page Code Monkey logo

node-worker's Introduction

node-worker - 0.0.1

node-worker is an implementation of the WebWorker API for node.js. http://www.whatwg.org/specs/web-workers/current-work/

Example

var Worker = require("../lib/worker").Worker;

var worker = new Worker("worker.js");

worker.postMessage({
  hello: "world"
});

worker.onmessage = function (msg) {
  sys.puts(msg.hello);
};

worker.addListener("message", function (msg) {
  sys.puts(msg.hello);
  worker.terminate();
});

Example Worker File

var worker = require("worker").worker;

worker.onmessage = function (msg) {
  worker.postMessage({
    hello: "mother"
  });
};

node-worker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-worker's Issues

Original message being sent to worker

Using the example in an express application and calling posting a message to a worker will return 2 messages from the worker.

  1. The original message sent to the worker
  2. The message from the worker

Is this the expected behavior ?

addListener doesn't work inside the worker

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.