JSPM

worker-routine

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q20765F
  • License MIT

Inline, Promise based wrapper around JS Web Workers.

Package Exports

  • worker-routine

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (worker-routine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Routine

Inline, Promise based wrapper around JS Web Workers

GitHub npm

yarn add worker-routine

Usage

Using async / await:

import routine from "worker-routine";

const inneficientSquare = n => {
  let total = 0;
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < n; j++) {
      total++;
    }
  }
  return total;
};

// spawns two workers running in separate threads
const results = await Promise.all([
  routine(inneficientSquare, 80000),
  routine(inneficientSquare, 80001)
]);

console.log(results[0] * results[1]);

Using Promise.then:

import routine from "worker-routine";

const multiply = (a, b, c) => a * b * c;

routine(multiply, 2, 3, 10).then(
  console.log // => 60
);