Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinychang/ptq
Promise task queue
https://github.com/shinychang/ptq
promise queue task
Last synced: 24 days ago
JSON representation
Promise task queue
- Host: GitHub
- URL: https://github.com/shinychang/ptq
- Owner: ShinyChang
- Created: 2017-11-11T02:51:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-15T02:18:46.000Z (over 6 years ago)
- Last Synced: 2024-04-14T07:56:48.981Z (7 months ago)
- Topics: promise, queue, task
- Language: JavaScript
- Size: 40 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ptq
## How to use
### 1. Simple task queue
```jsx
import TaskQueue from 'ptq'const options = {
concurrent: 10,
interval: 0
}
const queue = [1, 2, 3, 4, 5]
const task = (num) => {
return new Promise((resolve) => {
resolve(num)
})
}new TaskQueue(queue, task, options).start()
```### 2. Generate thumbnail task
```jsx
import {promisify} from 'util';
import TaskQueue from 'ptq'
import path from 'path';
import sharp from 'sharp';
import glob from 'glob';
const globPromisify = promisify(glob);const dest = `${path.resolve(__dirname)}/160`;
globPromisify(`${path.resolve(__dirname)}/480/*`).then(files => {
const task = file => {
const filename = file.split('/').pop();
return sharp(file).toFile(`${dest}/${filename}`);
};
new TaskQueue(files, task, {concurrent: 255}).start();
});
```