Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tom910/frame-scheduling
Asynchronous non-blocking running many tasks in JavaScript. Demo https://codesandbox.io/s/admiring-ride-jdoq0
https://github.com/tom910/frame-scheduling
async asynctask requestanimationframe scheduled-jobs scheduled-tasks scheduler scheduling tasks
Last synced: about 1 month ago
JSON representation
Asynchronous non-blocking running many tasks in JavaScript. Demo https://codesandbox.io/s/admiring-ride-jdoq0
- Host: GitHub
- URL: https://github.com/tom910/frame-scheduling
- Owner: Tom910
- License: mit
- Created: 2017-10-22T15:46:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T15:15:07.000Z (almost 2 years ago)
- Last Synced: 2024-11-07T06:26:06.202Z (about 2 months ago)
- Topics: async, asynctask, requestanimationframe, scheduled-jobs, scheduled-tasks, scheduler, scheduling, tasks
- Language: TypeScript
- Homepage:
- Size: 1.81 MB
- Stars: 68
- Watchers: 4
- Forks: 4
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/Tom910/frame-scheduling.svg?branch=master)](https://travis-ci.org/Tom910/frame-scheduling)
[![Coverage Status](https://coveralls.io/repos/github/Tom910/frame-scheduling/badge.svg?branch=master)](https://coveralls.io/github/Tom910/frame-scheduling?branch=master)# Frame Scheduling
A tiny module which allows run a non-blocking layout many tasks.* **Fast.** Contains low overhead and optimized for running lots of tasks without drop fps
* **Small.** 930 B (minified and gzipped). No dependencies. It uses [Size Limit](https://github.com/ai/size-limit) to control size.
* **Priority** Separate tasks into different priorities. Try to complete priority tasks as quickly as possible.
* **Isomorphic.** work in browser and node js.```js
import frameScheduling, { P_IMPORTANT } from 'frame-scheduling';frameScheduling(() => { console.log('async task') });
```
[Demo](https://codesandbox.io/s/admiring-ride-jdoq0)Asynchronous running tasks in JavaScript based on requestAnimationFrame. Supports priority and interrupt execution every 16 milliseconds, to achieve 60fps.
## Installation
```bash
# yarn
yarn add frame-scheduling# npm
npm install --save frame-scheduling
```## Priority
```js
import frameScheduling, { P_IMPORTANT, P_LOW } from 'frame-scheduling';
const result = [];frameScheduling(() => { result.push('A') }, { priority: P_LOW })
frameScheduling(() => { result.push('B') })
frameScheduling(() => { result.push('C') }, { priority: P_IMPORTANT })
frameScheduling(() => { result.push('D') }, { priority: 1000 })// after doing
console.log(result) // > ['D', 'C', 'B', 'A']
```
perform priority tasks first### framing
```js
import frameScheduling from 'frame-scheduling';frameScheduling(() => lightFunction()) // light < 1ms exec
frameScheduling(() => heavyFunction()) // heavy > 17ms exec
frameScheduling(() => heavyFunction2()) // heavy > 17ms exec
frameScheduling(() => lightFunction2()) // light < 1ms exec
frameScheduling(() => lightFunction3()) // light < 1ms exec/*
Runs in frame
| lightFunction
| heavyFunction
| heavyFunction2
| lightFunction2
| lightFunction3
*/
```
frame-scheduling aims to achieve 60 fps## Options
#### priority: number = 5
It is possible to set the priority of the function. If the function has a low priority, then each execution skip adds +1 to the priority. Thus, low-priority tasks, when something is done.