|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | /** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
|
|---|
| 9 |
|
|---|
| 10 | /**
|
|---|
| 11 | * @template T
|
|---|
| 12 | * @template Z
|
|---|
| 13 | * @callback Iterator
|
|---|
| 14 | * @param {T} item item
|
|---|
| 15 | * @param {(err?: null | Error, result?: null | Z) => void} callback callback
|
|---|
| 16 | * @param {number} i index
|
|---|
| 17 | * @returns {void}
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | /**
|
|---|
| 21 | * @template T
|
|---|
| 22 | * @template Z
|
|---|
| 23 | * @param {T[]} array array
|
|---|
| 24 | * @param {Iterator<T, Z>} iterator iterator
|
|---|
| 25 | * @param {(err?: null | Error, result?: null | Z, i?: number) => void} callback callback after all items are iterated
|
|---|
| 26 | * @returns {void}
|
|---|
| 27 | */
|
|---|
| 28 | module.exports = function forEachBail(array, iterator, callback) {
|
|---|
| 29 | if (array.length === 0) return callback();
|
|---|
| 30 |
|
|---|
| 31 | let i = 0;
|
|---|
| 32 | const next = () => {
|
|---|
| 33 | /** @type {boolean | undefined} */
|
|---|
| 34 | let loop;
|
|---|
| 35 | iterator(
|
|---|
| 36 | array[i++],
|
|---|
| 37 | (err, result) => {
|
|---|
| 38 | if (err || result !== undefined || i >= array.length) {
|
|---|
| 39 | return callback(err, result, i);
|
|---|
| 40 | }
|
|---|
| 41 | if (loop === false) while (next());
|
|---|
| 42 | loop = true;
|
|---|
| 43 | },
|
|---|
| 44 | i,
|
|---|
| 45 | );
|
|---|
| 46 | if (!loop) loop = false;
|
|---|
| 47 | return loop;
|
|---|
| 48 | };
|
|---|
| 49 | while (next());
|
|---|
| 50 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.