Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Zaynex/x-atm
async task manager
https://github.com/Zaynex/x-atm
async promise task-manager
Last synced: 16 days ago
JSON representation
async task manager
- Host: GitHub
- URL: https://github.com/Zaynex/x-atm
- Owner: Zaynex
- License: mit
- Created: 2019-06-10T03:45:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T07:56:32.000Z (over 1 year ago)
- Last Synced: 2024-09-25T11:26:07.774Z (about 2 months ago)
- Topics: async, promise, task-manager
- Language: TypeScript
- Homepage: https://zaynex.github.io/x-atm/
- Size: 1.77 MB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# Async Task Manager
> A JavaScript library for controlling asynchronous parallelism.*其他语言版本: [简体中文](README.zh.md)*
## Background
`x-atm` is designed to help you control asynchronous tasks.
For example, in parallel file uploading, most browsers only support 6 paralle http requests. If you don't control async tasks(http request), it will block the request stack, and cause performance problem. But with `x-atm`, we can control the number of asynchronous requests to improve the upload efficiency.## Installation
```
yarn add x-atm
```## Basic usage
```javascript
const ATM = require('x-atm');
function handleAll() {
console.log("all task resolved");
}let task = new ATM({maxParallel: 4,resolve: handleAll, strict: true});
const asyncTask = (index) => {
return new Promise((resolve, reject) => {
let random = parseInt(Math.random() * 10000);
setTimeout(() => {
if (random > 5000) {
resolve('value is ' + random + ' current task ' + index);
} else {
reject('reason is ' + random + ' current task ' + index);
}
}, random);
});
}
asyncTask.resolve = console.log
asyncTask.reject = console.log
for(let i = 0; i < 10; i++) {
task.push(asyncTask);
}task.start();
```