Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tinybug/parallel-your-tasks
parallel running your tasks
https://github.com/tinybug/parallel-your-tasks
Last synced: about 1 month ago
JSON representation
parallel running your tasks
- Host: GitHub
- URL: https://github.com/tinybug/parallel-your-tasks
- Owner: tinybug
- Created: 2016-06-18T08:33:35.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-24T07:15:42.000Z (over 8 years ago)
- Last Synced: 2024-04-24T20:13:31.132Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
parallel running your tasks
Here is the simple example:
```js
function createTask() {
const randomTime = Math.floor(Math.random() * 10000 % 10000);
return () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (randomTime > 5000) {
resolve();
} else {
reject(`run error ${randomTime}`);
}
}, randomTime);
});
};
}const tasks = [];
for (let i = 0; i < 20; ++i) {
tasks[i] = createTask();
}const pyt = PYT();
pyt.on('done', (report) => {
console.log('all task done');
});// parallel running 10 tasks
pyt.init(tasks, 10);
pyt.start();
```