@ditojs/utils 1.25.0 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/utils",
3
- "version": "1.25.0",
3
+ "version": "1.26.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/utils",
@@ -32,7 +32,7 @@
32
32
  "typescript": "^4.9.5"
33
33
  },
34
34
  "types": "types",
35
- "gitHead": "29e7f8d8c613c48a856d90d1ee876e85c8d84c08",
35
+ "gitHead": "198c9832c863003c8c8fcd147bf61a5f99a39c91",
36
36
  "scripts": {
37
37
  "types": "tsc --noEmit types/index.d.ts"
38
38
  },
@@ -1,32 +1,33 @@
1
1
  export async function mapConcurrently(
2
2
  input,
3
3
  callback,
4
- { concurrency = null } = {}
4
+ { concurrency = 0 } = {}
5
5
  ) {
6
6
  const array = await input
7
- if (concurrency === null) {
7
+ if (!concurrency) {
8
8
  return Promise.all(array.map(callback))
9
- } else {
10
- const promises = []
11
- const results = []
12
- let index = 0
9
+ }
13
10
 
14
- function next() {
15
- if (index < array.length) {
16
- const i = index++
17
- return Promise.resolve(callback(array[i], i, array)).then(result => {
18
- results[i] = result
19
- return next()
20
- })
21
- }
22
- }
11
+ const promises = []
12
+ const results = []
13
+ let index = 0
23
14
 
24
- while (concurrency-- > 0) {
25
- const promise = next()
26
- if (!promise) break
27
- promises.push(promise)
15
+ function next() {
16
+ if (index < array.length) {
17
+ const i = index++
18
+ return Promise.resolve(callback(array[i], i, array)).then(result => {
19
+ results[i] = result
20
+ return next()
21
+ })
28
22
  }
23
+ return null
24
+ }
29
25
 
30
- return Promise.all(promises).then(() => results)
26
+ while (concurrency-- > 0) {
27
+ const promise = next()
28
+ if (!promise) break
29
+ promises.push(promise)
31
30
  }
31
+
32
+ return Promise.all(promises).then(() => results)
32
33
  }