worker-builder
v0.0.1
Published
A library to simplify the usage of Webworkers
Downloads
15
Maintainers
Readme
worker-builder
This library will only work inside a webpack bundle
Usage
run
Applies a givent method on a given argument inside a WebWorker instance.
The worker method runs in its own context, but you can use imported libraries.
Example:
import * as workerBuilder from "worker-builder";
import * as _ from "underscore";
workerBuilder.run<{start: number, end: number},number[]>({start: 0, end: 100},options=>{
function isPrime(canidate: number): boolean{
for(let i=canidate-1;i>1;i--){
if(canidate % i == 0){
return false;
}
}
return true;
}
return _.range(options.start,options.end).filter(isPrime);
})
.then(result=>{
document.writeln(result.toString());
});