UNPKG

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