Home

Awesome

node-webworkers is an implementation of the Web Workers API for node.js.

See the design document here.

Example

Master source

var sys = require('sys');
var Worker = require('webworker');

var w = new Worker('foo.js');

w.onmessage = function(e) {
    sys.debug('Received mesage: ' + sys.inspect(e));
    w.terminate();
};

w.postMessage({ foo : 'bar' });

Worker source

onmessage = function(e) {
    postMessage({ test : 'this is a test' });
};

onclose = function() {
    sys.debug('Worker shuttting down.');
};

API

Supported API methods are

In addition, some nonstandard APIs are provided

Installation

This package can be installed via npm as follows

% npm install webworker

Note that this requires node-websocket-client v0.9.3 or later. This dependency will be handled automatically by npm, but must be dealt with manually if installing using another procedure.

Credits

This package contains a static snapshot of Micheil Smith's excellent node-websocket-server with some fixes applied to handle UNIX sockets.