t-tasks 2.1.0 → 2.1.1
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/t-tasks.d.ts +2 -2
- package/dist/t-tasks.esm.js +29 -20
- package/dist/t-tasks.esm.js.map +1 -1
- package/dist/t-tasks.js +29 -20
- package/dist/t-tasks.js.map +1 -1
- package/package.json +1 -1
- package/src/task.ts +34 -29
package/dist/t-tasks.js
CHANGED
|
@@ -519,31 +519,40 @@ let Task;
|
|
|
519
519
|
}
|
|
520
520
|
_Task.all = all;
|
|
521
521
|
function any(tasks) {
|
|
522
|
-
const cell = settleCell();
|
|
523
522
|
const taskArray = Array.from(tasks);
|
|
524
|
-
if (taskArray.length
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
523
|
+
if (taskArray.length === 0) return Task.rejected([]);
|
|
524
|
+
return Task.fromCallback((resolve, reject, cancel) => {
|
|
525
|
+
const errors = taskArray.map(() => Maybe.nothing());
|
|
526
|
+
let remaining = taskArray.length;
|
|
527
|
+
const checkAllFailed = () => {
|
|
528
|
+
remaining--;
|
|
529
|
+
if (remaining === 0) reject(errors.map((e) => e.match({
|
|
530
|
+
just: (err) => err,
|
|
531
|
+
nothing: () => void 0
|
|
532
|
+
})));
|
|
533
|
+
};
|
|
534
|
+
taskArray.forEach((task, i) => {
|
|
535
|
+
task.matchTap({
|
|
536
|
+
resolved: (value) => {
|
|
537
|
+
resolve(value);
|
|
538
|
+
taskArray.forEach((t) => t.cancel());
|
|
539
|
+
},
|
|
540
|
+
rejected: (error) => {
|
|
541
|
+
errors[i] = Maybe.just(error);
|
|
542
|
+
checkAllFailed();
|
|
543
|
+
},
|
|
544
|
+
canceled: () => {
|
|
545
|
+
cancel();
|
|
546
|
+
taskArray.forEach((t) => t.cancel());
|
|
547
|
+
}
|
|
548
|
+
});
|
|
540
549
|
});
|
|
541
|
-
|
|
542
|
-
|
|
550
|
+
return taskArray;
|
|
551
|
+
}, (subtasks) => subtasks.forEach((t) => t.cancel()));
|
|
543
552
|
}
|
|
544
553
|
_Task.any = any;
|
|
545
554
|
function limit(task, limitTask) {
|
|
546
|
-
return Task.any([task, limitTask.chain(Task.canceled)])
|
|
555
|
+
return Task.any([task, limitTask.chain(Task.canceled)]);
|
|
547
556
|
}
|
|
548
557
|
_Task.limit = limit;
|
|
549
558
|
function repeat(taskFunction) {
|