2.1.2 • Published 7 years ago

proxyworker v2.1.2

Weekly downloads
10
License
MPL-2.0
Repository
github
Last release
7 years ago

proxyworker

CircleCI

Lightweight utility to proxy api requests from main thread to web worker. Run the tests in your browser here!

Usage

// Main thread
const {ProxyWorker} = require('proxyworker');

const worker = new ProxyWorker(new Worker('./path/to/worker.js'));

// Call 'echo' method on worker with some arguments.
// This returns a promise that will resolve with the worker api response.
worker.callWithArgs('echo', ['a', 'b', 'c', 1, 2, 3]);

// Subscribe to worker event.
worker.subscribe('breakfast', breakfast => {
  // breakfast => ['green', 'eggs', 'and', 'tofu']
});
// worker.js
const {emit, proxy} = require('proxyworker');

proxy({
  methods: {
    echo: function() {
      let result = Array.prototype.slice.call(arguments);
      return Promise.resolve(result);
    }
  },

  events: [
    'breakfast',
  ]
});

// Time for breakfast?
setInterval(function() {
  emit('breakfast', [
    'green',
    'eggs',
    'and',
    'tofu',
  ]);
}, 24 * 60 * 60 * 1000);
2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.4.0

9 years ago

1.3.5

10 years ago

1.3.4

10 years ago

1.3.3

10 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago