ino-worker
v1.0.6
Published
A utility to create and run web worker scripts directly from strings.
Downloads
13
Maintainers
Readme
import { RunInWorker } from "ino-worker";
// The function to be executed in the web worker
const myFunction = (count) => {
let sum = 0;
for (let i = 0; i < count; i++) {
sum += i;
}
return sum;
};
// or you can use a string representation of the function
const myFunction = `(count) => {
let sum = 0;
for (let i = 0; i < count; i++) {
sum += i;
}
return sum;
}`;
const arg = 100000000;
// Call RunInWorker with the function and its arguments to execute it in a web worker
RunInWorker(myFunction, arg)
.then((sum) => {
console.log("Result from worker ", sum);
})
.catch((err) => {
console.error(err);
});