1 | import { canUseAsyncIteratorSymbol } from "../../../utilities/index.js";
|
2 | export default function promiseIterator(promise) {
|
3 | var resolved = false;
|
4 | var iterator = {
|
5 | next: function () {
|
6 | if (resolved)
|
7 | return Promise.resolve({
|
8 | value: undefined,
|
9 | done: true,
|
10 | });
|
11 | resolved = true;
|
12 | return new Promise(function (resolve, reject) {
|
13 | promise
|
14 | .then(function (value) {
|
15 | resolve({ value: value, done: false });
|
16 | })
|
17 | .catch(reject);
|
18 | });
|
19 | },
|
20 | };
|
21 | if (canUseAsyncIteratorSymbol) {
|
22 | iterator[Symbol.asyncIterator] = function () {
|
23 | return this;
|
24 | };
|
25 | }
|
26 | return iterator;
|
27 | }
|
28 |
|
\ | No newline at end of file |