Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kezhengjie/concurrency_js
a js file that implement concurrency async operation which could limit concurrency nums.
https://github.com/kezhengjie/concurrency_js
async async-javascript batch concurrency javascript promise thread-like
Last synced: 6 days ago
JSON representation
a js file that implement concurrency async operation which could limit concurrency nums.
- Host: GitHub
- URL: https://github.com/kezhengjie/concurrency_js
- Owner: kezhengjie
- License: mit
- Created: 2021-07-09T08:22:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-14T06:55:25.000Z (over 3 years ago)
- Last Synced: 2024-12-25T03:22:14.613Z (10 days ago)
- Topics: async, async-javascript, batch, concurrency, javascript, promise, thread-like
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# concurrency_js
a js file that implement concurrency async operation which could limit concurrency nums.usage :
```
C.add(asyncFuncPrototype,...args)
C.wait().then(()=>{console.log("all done")})
```
remember to resolve() in your async function other wise queue will be blocked.default concurreny num is 5
```
C.setMaxRunning(10) to change concurrency num.
```// look demo for more detail.
```
function demo() {
function timeToPrint(t) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(t)
resolve()
})
})
}setTimeout(() => {
for (let i = 1; i < 100; i++) {
let t = i
C.add(timeToPrint, t)
}
}, 100)setTimeout(() => {
for (let i = 1; i < 100; i = i + 5) {
let t = i
C.add(timeToPrint, t)
}
}, 2000)setTimeout(() => {
for (let i = 1; i < 100; i = i + 3) {
let t = i
C.add(timeToPrint, t)
}
}, 5000)C.wait().then(() => {
console.log("all done")
})
}
```