1 | import _Symbol from "@babel/runtime-corejs3/core-js/symbol";
|
2 | import _Symbol$asyncIterator from "@babel/runtime-corejs3/core-js/symbol/async-iterator";
|
3 | import _Symbol$iterator from "@babel/runtime-corejs3/core-js/symbol/iterator";
|
4 | import _Promise from "@babel/runtime-corejs3/core-js/promise";
|
5 | export default function _asyncIterator(iterable) {
|
6 | var method,
|
7 | async,
|
8 | sync,
|
9 | retry = 2;
|
10 |
|
11 | for ("undefined" != typeof _Symbol && (async = _Symbol$asyncIterator, sync = _Symbol$iterator); retry--;) {
|
12 | if (async && null != (method = iterable[async])) return method.call(iterable);
|
13 | if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
14 | async = "@@asyncIterator", sync = "@@iterator";
|
15 | }
|
16 |
|
17 | throw new TypeError("Object is not async iterable");
|
18 | }
|
19 |
|
20 | function AsyncFromSyncIterator(s) {
|
21 | function AsyncFromSyncIteratorContinuation(r) {
|
22 | if (Object(r) !== r) return _Promise.reject(new TypeError(r + " is not an object."));
|
23 | var done = r.done;
|
24 | return _Promise.resolve(r.value).then(function (value) {
|
25 | return {
|
26 | value: value,
|
27 | done: done
|
28 | };
|
29 | });
|
30 | }
|
31 |
|
32 | return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) {
|
33 | this.s = s, this.n = s.next;
|
34 | }, AsyncFromSyncIterator.prototype = {
|
35 | s: null,
|
36 | n: null,
|
37 | next: function next() {
|
38 | return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
39 | },
|
40 | "return": function _return(value) {
|
41 | var ret = this.s["return"];
|
42 | return void 0 === ret ? _Promise.resolve({
|
43 | value: value,
|
44 | done: !0
|
45 | }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
46 | },
|
47 | "throw": function _throw(value) {
|
48 | var thr = this.s["return"];
|
49 | return void 0 === thr ? _Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
50 | }
|
51 | }, new AsyncFromSyncIterator(s);
|
52 | } |
\ | No newline at end of file |