web-threads
Version:
generic threads using web workers for the web
107 lines (87 loc) • 2.99 kB
Markdown
[](https://travis-ci.org/kanekotic/web-threads)
[](https://codecov.io/gh/kanekotic/web-threads)
[](https://github.com/kanekotic/web-threads)
[](https://github.com/kanekotic/web-threads/blob/master/LICENSE)
[](https://GitHub.com/kanekotic/web-threads/graphs/commit-activity)
generic threads using web workers for the web
add it to your project using `npm install web-threads --save` or `yarn add web-threads`
```js
import { execute } from 'web-threads'
let func = (value) => {
return value * value
}
let params = {
fn: func.toString(),
args: [2]
}
execute(params)
.then(console.log)
.catch(console.error)
```
```js
import { execute } from 'web-threads'
function Func(value){
this.value = value
}
Func.prototype.foo = function(){
return this.value * this.value
};
var instance = new Func(2)
let params = {
fn: instance.foo,
context: instance
}
execute(params)
.then(console.log)
.catch(console.error)
```
```js
import { execute } from 'web-threads'
function Func(value){
this.value = value
}
Func.prototype.foo = function(otherValue){
return this.value * otherValue
};
var instance = new Func(2)
let params = {
fn: instance.foo,
context: instance,
args: [4]
}
execute(params)
.then(console.log)
.catch(console.error)
```
```js
import { execute } from 'web-threads'
class someClass {
constructor(val){
this.val = val
}
foo(some){
return this.val * some
}
}
var instance = new someClass(2)
let params = {
fn: instance.foo,
context: instance,
args: [4]
}
execute(params)
.then(console.log)
.catch(console.error)
```
- [work done pairing with @kmruiz for ui.wind.js](https://github.com/CodeInBrackets/ui.wind.js)
- [scottlogic.com post](https://blog.scottlogic.com/2011/02/24/web-workers-part-3-creating-a-generic-worker.html)
- [@vkiryukhin](http://www.eslinstructor.net/vkthread/)