Skip to content

Use Web workers to allow complex computing without affecting page performance

Notifications You must be signed in to change notification settings

linxiangjun/complex-calculations-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

complex-calculations-worker

Use Web workers to allow complex computing without affecting page performance

Install

npm install complex-calculations-worker

Usage

import { useWorker } from 'complex-calculations-worker'

useWorker(event).then(res => {
  // do something
});

Example

without web worker

const runTime = Date.now();
console.log(runTime);

for (let i = 0; i < 10000000; i++) {
// do something
}

console.log(Date.now() - runTime); // 10 milliseconds or more

use web worker

const runTime = Date.now();
console.log(runTime);

useWorker(() => {
  for (let i = 0; i < 10000000; i++) {
    // do something
  }
  return 'finish';
}).then(res => {
  console.log(res);
});

// time
console.log(Date.now() - runTime); // within 5 milliseconds

About

Use Web workers to allow complex computing without affecting page performance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published