web-threads
v1.0.135
Published
generic threads using web workers for the web
Downloads
324
Maintainers
Readme
generic threads using web workers for the web
Installation
add it to your project using npm install web-threads --save
or yarn add web-threads
Usage
Simple function with arguments
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)
Function with context
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)
Function with context and arguments
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)
ES6 class call function with arguments
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)