Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ayecue/non-blocking-schedule
Useful for non blocking scheduling of tasks. Good alternative to setTimeout(cb, 0)
https://github.com/ayecue/non-blocking-schedule
Last synced: 15 days ago
JSON representation
Useful for non blocking scheduling of tasks. Good alternative to setTimeout(cb, 0)
- Host: GitHub
- URL: https://github.com/ayecue/non-blocking-schedule
- Owner: ayecue
- License: mit
- Created: 2024-07-21T16:11:12.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-17T13:44:17.000Z (5 months ago)
- Last Synced: 2024-11-30T18:52:16.686Z (about 2 months ago)
- Language: TypeScript
- Size: 268 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# non-blocking-schedule
[![non-blocking-schedule](https://circleci.com/gh/ayecue/non-blocking-schedule.svg?style=svg)](https://circleci.com/gh/ayecue/non-blocking-schedule)
The non-blocking-schedule library is a robust utility designed to facilitate non-blocking task scheduling, ensuring efficient execution of queued tasks without hindering the performance of other operations. This library is particularly useful for applications that require precise control over task execution timing and concurrency.
## Installation
```sh
npm install --save non-blocking-schedule
```## Example
```js
import { schedule } from "non-blocking-schedule";const MAX_OPS = 10;
const processInChunks = (ops) => {
for (let i = 0; i < MAX_OPS; i++) {
ops[i]();
}
const remaining = ops.slice(MAX_OPS);
if (remaining.length === 0) return;
schedule(processInChunks.bind(null, remaining));
};const exampleOps = new Array(1000).fill(() => {
console.log('random test string', (Math.random() + 1).toString(36).substring(7));
});processInChunks(exampleOps);
```## Performance
Results from `benchmark.ts`.
```
Chrome:
setTimeout - Avg 5321.423
setImmediate (polyfill) - Avg 9798.79
non-blocking-schedule - Avg 3726.29
``````
NodeJS:
setTimeout - Avg 8170.55
setImmediate - Avg 7749.52
non-blocking-schedule - Avg 6791.65
```