Map a Kefir stream to a WebWorker
Install using bower or npm
bower install kefir-webworker
npm install kefir-webworker
User mapWithWorker
in your main javascript:
Kefir.emitter()
.mapWithWorker(new Worker('echo-worker-bundle.js'))
.log('web-worker');
emitter.emit('hello');
emitter.error('oh no!');
Use Kefir.fromMessage
and toMessage
in your webworker:
// Make sure you include Kefir and kefir-webworker:
var Kefir = require('kefir');
require('kefir-webworker');
Kefir
.fromMessage() // Create stream from incoming messages
.delay(1000)
.toMessage(); // Post messages back to main javascript
You have to bundle your code (i.e. example/echo-worker.js
) with Kefir and kefir-webworker.
In the example, I am using webpack to bundle the files:
npm install # install dependencies
npm install webpack -g
webpack --entry ./example/echo-worker --output-file ./example/echo-worker-bundle.js
- Initial Release
Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.
- @markmarijnissen
- http://www.madebymark.nl
- info@madebymark.nl
© 2015 - Mark Marijnissen