2.1.2 • Published 6 years ago

proxyworker v2.1.2

Weekly downloads
10
License
MPL-2.0
Repository
github
Last release
6 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

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.4.0

8 years ago

1.3.5

9 years ago

1.3.4

9 years ago

1.3.3

9 years ago

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago