Socket
Book a DemoInstallSign in
Socket

worker-component

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-component

Web worker API wrapper

npmnpm
Version
0.0.1
Version published
Weekly downloads
4
300%
Maintainers
1
Weekly downloads
 
Created
Source

worker

Web worker API wrapper.

Installation

$ component install component/worker

Example

var Worker = require('worker');
var worker = new Worker('work.js');

worker.on('message', function(msg, e){
  if (!msg.progress) return worker.off('message');
  console.log(msg.progress);
});

worker.send({ id: 1 });

API

Worker(script)

Initialize a worker with the given script.

Worker#send(msg)

Send a message to the worker.

worker.send({ string: 'hello' });
worker.send({ string: 'world' });

Worker#send(msg, callback)

Send a request message to the worker with the given callback. When using the request/response paradigm you should pass the e.data.id property back with your response so that the correct callback may be invoked:

onmessage = function(e) {
  setTimeout(function(){
    postMessage({ id: e.data.id, value: e.data.value.toUpperCase() });
  }, 500);
};

Worker#close()

Terminate the worker.

License

MIT

FAQs

Package last updated on 19 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts