source: imaps-frontend/node_modules/@babel/core/lib/gensync-utils/async.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.forwardAsync = forwardAsync;
7exports.isAsync = void 0;
8exports.isThenable = isThenable;
9exports.maybeAsync = maybeAsync;
10exports.waitFor = exports.onFirstPause = void 0;
11function _gensync() {
12 const data = require("gensync");
13 _gensync = function () {
14 return data;
15 };
16 return data;
17}
18function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20const runGenerator = _gensync()(function* (item) {
21 return yield* item;
22});
23const isAsync = exports.isAsync = _gensync()({
24 sync: () => false,
25 errback: cb => cb(null, true)
26});
27function maybeAsync(fn, message) {
28 return _gensync()({
29 sync(...args) {
30 const result = fn.apply(this, args);
31 if (isThenable(result)) throw new Error(message);
32 return result;
33 },
34 async(...args) {
35 return Promise.resolve(fn.apply(this, args));
36 }
37 });
38}
39const withKind = _gensync()({
40 sync: cb => cb("sync"),
41 async: function () {
42 var _ref = _asyncToGenerator(function* (cb) {
43 return cb("async");
44 });
45 return function async(_x) {
46 return _ref.apply(this, arguments);
47 };
48 }()
49});
50function forwardAsync(action, cb) {
51 const g = _gensync()(action);
52 return withKind(kind => {
53 const adapted = g[kind];
54 return cb(adapted);
55 });
56}
57const onFirstPause = exports.onFirstPause = _gensync()({
58 name: "onFirstPause",
59 arity: 2,
60 sync: function (item) {
61 return runGenerator.sync(item);
62 },
63 errback: function (item, firstPause, cb) {
64 let completed = false;
65 runGenerator.errback(item, (err, value) => {
66 completed = true;
67 cb(err, value);
68 });
69 if (!completed) {
70 firstPause();
71 }
72 }
73});
74const waitFor = exports.waitFor = _gensync()({
75 sync: x => x,
76 async: function () {
77 var _ref2 = _asyncToGenerator(function* (x) {
78 return x;
79 });
80 return function async(_x2) {
81 return _ref2.apply(this, arguments);
82 };
83 }()
84});
85function isThenable(val) {
86 return !!val && (typeof val === "object" || typeof val === "function") && !!val.then && typeof val.then === "function";
87}
880 && 0;
89
90//# sourceMappingURL=async.js.map
Note: See TracBrowser for help on using the repository browser.