webworkio

1.0.0 • Public • Published

Webworkio

Purpose

This class helps you deal with web-workers in a way which looks like the way socket.io does with websockets.

The purpose of this class is to greatly simplify the use of web workers and to mimic socket.io's callback feature.

Basically, an application emits a message to a webworker, providing a callback function (CB). The webworker will call CB after completing its task. The application will then be notify back and receive any data passed as argument to CB.

example

Application.js

class Application {
    run() {
        this.wwio = new Webworkio();
     this.wwio.worker('./myworker.js');
     this.wwio.emit('test', {msg: 'hello'}, function(result) {
            console.log('web worker initialized', result);
        });
    }
}

myworker.js

const wwio = new Webworkio();
wwio.worker();
wwio.on('test', function ({msg}, cb) {
  if (msg === 'hello') {
    cb('hello world');
  } else {
    cb('');
  }
});

Readme

Keywords

Package Sidebar

Install

npm i webworkio

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

117 kB

Total Files

15

Last publish

Collaborators

  • laboralphy