cycle-webworker
v2.1.0
Published
A straightforward webworker driver for Cycle.js
Downloads
2
Readme
cycle-webworker
A straightforward webworker driver for Cycle.js
This module allows you to send and receive messages to Web Workers with Cycle.js.
If you have not used Web Workers before, please see the MDN documentation.
Usage
import {makeWebWorkerDriver} from 'cycle-webworker';
import {run} from '@cycle/run';
const drivers = {
Worker: makeWebWorkerDriver(new Worker('/worker.js'))
}
function main (sources) {
const result$ = sources.Worker;
const outgoingMessage$ = xs.of('test!');
return {
Worker: outgoingMessage$
}
}
run(main, drivers);
There is a working example in example/
. To run it, clone this project, npm install && npm start
.
API
import {makeWebWorkerDriver} from 'cycle-webworker';
makeWebWorkerDriver
takes a single argument, the worker.
This is generally constructed by calling new Worker()
with a source url for the worker code, but also allows for use of libraries like webworkify.
Please see the MDN documentation for documentation around creating workers.
The resulting driver takes a stream of messages to send to the worker as sinks, and returns a stream of messages from the worker.
Install
With npm installed, run
$ npm install cycle-webworker
License
MIT