generic threads using web workers for the web
add it to your project using npm install web-threads --save
or yarn add web-threads
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)
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)
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)
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)