()
| 44 | let index = 0; |
| 45 | return { |
| 46 | async next() { |
| 47 | if (index < cache.length) { |
| 48 | return { value: cache[index++], done: false }; |
| 49 | } |
| 50 | if (done) { |
| 51 | return { value: undefined, done: true }; |
| 52 | } |
| 53 | index++; |
| 54 | if (!is.promise(nextElement)) { |
| 55 | nextElement = iterable[Symbol.asyncIterator]().next().then(element => { |
| 56 | if (!(done = element.done)) { |
| 57 | cache.push(element.value); |
| 58 | } |
| 59 | nextElement = undefined; |
| 60 | return element; |
| 61 | }); |
| 62 | } |
| 63 | return nextElement; |
| 64 | } |
| 65 | }; |
| 66 | } |
| 67 | }; |