thaw.js
v2.1.4
Published
synthetic asynchronous processing in javascript
Downloads
10,543
Maintainers
Readme
Thaw.js
synthetic asynchronous processing in javascript
Thaw.js helps keep the browser from freezing by splitting long computations into small parts which are processed more naturally when the browser isn't busy. This simulates asynchronous behaviour and attempts to keep the browser from freezing. Thaw.ts thaws frozen browsers.
Usage
import { thaw } from 'thaw.js';
import { matrixMultiply } from 'fake-math-library';
let lastMatrix;
const items = [];
for (let i = 0; i < 1000000; i++) {
items.push(() => {
lastMatrix = matrixMultiply(a, b);
});
}
// start thawing!
const t = thaw(items);
//sometime later
t.add(item); // append single function to end of all tasks
t.insert(item); // insert single function after current task
t.addArray(items); // append array of functions to end of all tasks
t.insertArray(items); // insert array of functions after current task
// sometime perhaps even more later
t.stop(); // stop all tasks on this instance of thaw from thawing
t.stopAll(); // stop ALL INSTANCES of thaw from thawing
Block Usage
A "block" is a set number of thaw instances, so that setTimeout doesn't get over used. This can lead to better performance in some cases.
import { Block } from 'thaw';
const thaws = new Block(thawOptions, count);