npm.io
0.0.11 • Published 7 years ago

function-to-worker

Licence
MIT
Version
0.0.11
Deps
0
Size
12 kB
Vulns
0
Weekly
0

function-to-worker

function-to-worker is a package designed for run any synchronous functions in web workers scope. It lets to make calculations without blocking main js thread.

Usage

Package provide only one simple function which makes worker from passed function:

import createWorker from "function-to-worker";

const wantToCalculateItInWorker = number => number + 1;
const calculateInWorker = createWorker(wantToCalculateItInWorker);

function calculateInWorker from example above returns Promise which will resolved or rejected with value was returned by wantToCalculateItInWorker function. So, we can use it like this:

const addOneInWorker = async number => await calculateInWorker(number);

Keywords