@creejs/commons-lang 2.1.26 → 2.1.28
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/dist/cjs/index-dev.cjs +42 -2
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +42 -2
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +42 -2
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
- package/types/promise-utils.d.ts +2 -1
package/dist/cjs/index-dev.cjs
CHANGED
|
@@ -1541,6 +1541,45 @@ function safeToString (value) {
|
|
|
1541
1541
|
} else if (value === undefined) {
|
|
1542
1542
|
return 'undefined'
|
|
1543
1543
|
}
|
|
1544
|
+
const type = typeof value;
|
|
1545
|
+
if (type === 'string') {
|
|
1546
|
+
return value
|
|
1547
|
+
} else if (type === 'symbol') {
|
|
1548
|
+
return `Symbol(${value.description})`
|
|
1549
|
+
} else if (type === 'function') {
|
|
1550
|
+
return `Function ${value.name}(){}`
|
|
1551
|
+
}
|
|
1552
|
+
if (value instanceof String) {
|
|
1553
|
+
return value.toString()
|
|
1554
|
+
}
|
|
1555
|
+
if (Number.isNaN(value)) {
|
|
1556
|
+
return 'NaN'
|
|
1557
|
+
}
|
|
1558
|
+
if (value === Infinity) {
|
|
1559
|
+
return 'Infinity'
|
|
1560
|
+
}
|
|
1561
|
+
if (value === -Infinity) {
|
|
1562
|
+
return '-Infinity'
|
|
1563
|
+
}
|
|
1564
|
+
if (value instanceof Error) {
|
|
1565
|
+
return `${value.constructor.name}: ${value.message}`
|
|
1566
|
+
}
|
|
1567
|
+
if (value instanceof Promise) {
|
|
1568
|
+
return 'Promise'
|
|
1569
|
+
}
|
|
1570
|
+
if (value instanceof Set) {
|
|
1571
|
+
return `Set: ${safeToString(Array.from(value))}`
|
|
1572
|
+
}
|
|
1573
|
+
if (value instanceof Map) {
|
|
1574
|
+
return `Map: ${safeToString(Array.from(value.entries()))}`
|
|
1575
|
+
}
|
|
1576
|
+
if (value instanceof RegExp) {
|
|
1577
|
+
return value.toString()
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
if (Array.isArray(value)) {
|
|
1581
|
+
return `[${value.map(safeToString).join(', ')}]`
|
|
1582
|
+
}
|
|
1544
1583
|
let valueStr;
|
|
1545
1584
|
try {
|
|
1546
1585
|
valueStr = JSON.stringify(value);
|
|
@@ -2050,9 +2089,10 @@ async function parallelAllSettled (tasks, maxParallel = 5) {
|
|
|
2050
2089
|
* * One task failed, it will start next task immediately, Not Wait for the bulk(maxParallel) to complete
|
|
2051
2090
|
* @param {Array<Function|Promise<any>>} tasks - Array of async functions to execute
|
|
2052
2091
|
* @param {number} [maxParallel=5] - Maximum number of tasks to run in parallel
|
|
2092
|
+
* @param {string} [failureMessage] - Error message when all tasks failed
|
|
2053
2093
|
* @returns {Promise<any>} Resolves with the result of the first successfully completed task
|
|
2054
2094
|
*/
|
|
2055
|
-
async function parallelAny (tasks, maxParallel = 5) {
|
|
2095
|
+
async function parallelAny (tasks, maxParallel = 5, failureMessage) {
|
|
2056
2096
|
assertArray(tasks, 'tasks');
|
|
2057
2097
|
assertNumber(maxParallel);
|
|
2058
2098
|
if (tasks.length === 0) {
|
|
@@ -2097,7 +2137,7 @@ async function parallelAny (tasks, maxParallel = 5) {
|
|
|
2097
2137
|
// No task left, and No successful execution, reject with errors
|
|
2098
2138
|
if (errors.length >= tasks.length) {
|
|
2099
2139
|
if (deferred.pending) {
|
|
2100
|
-
deferred.reject(new AggregatedError('All Tasks Failed', errors));
|
|
2140
|
+
deferred.reject(new AggregatedError(failureMessage ?? 'All Tasks Failed', errors));
|
|
2101
2141
|
return
|
|
2102
2142
|
}
|
|
2103
2143
|
}
|