Created
November 9, 2021 10:01
-
-
Save mstoykov/a1bda1c66116b43f6bc4fe2153e645d2 to your computer and use it in GitHub Desktop.
Transpilation of a async await with babel so it can be used in k6 (with WIP event loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap | |
/******/ // The module cache | |
/******/ var installedModules = {}; | |
/******/ | |
/******/ // The require function | |
/******/ function __webpack_require__(moduleId) { | |
/******/ | |
/******/ // Check if module is in cache | |
/******/ if(installedModules[moduleId]) { | |
/******/ return installedModules[moduleId].exports; | |
/******/ } | |
/******/ // Create a new module (and put it into the cache) | |
/******/ var module = installedModules[moduleId] = { | |
/******/ i: moduleId, | |
/******/ l: false, | |
/******/ exports: {} | |
/******/ }; | |
/******/ | |
/******/ // Execute the module function | |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
/******/ | |
/******/ // Flag the module as loaded | |
/******/ module.l = true; | |
/******/ | |
/******/ // Return the exports of the module | |
/******/ return module.exports; | |
/******/ } | |
/******/ | |
/******/ | |
/******/ // expose the modules object (__webpack_modules__) | |
/******/ __webpack_require__.m = modules; | |
/******/ | |
/******/ // expose the module cache | |
/******/ __webpack_require__.c = installedModules; | |
/******/ | |
/******/ // define getter function for harmony exports | |
/******/ __webpack_require__.d = function(exports, name, getter) { | |
/******/ if(!__webpack_require__.o(exports, name)) { | |
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | |
/******/ } | |
/******/ }; | |
/******/ | |
/******/ // define __esModule on exports | |
/******/ __webpack_require__.r = function(exports) { | |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
/******/ } | |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
/******/ }; | |
/******/ | |
/******/ // create a fake namespace object | |
/******/ // mode & 1: value is a module id, require it | |
/******/ // mode & 2: merge all properties of value into the ns | |
/******/ // mode & 4: return value when already ns object | |
/******/ // mode & 8|1: behave like require | |
/******/ __webpack_require__.t = function(value, mode) { | |
/******/ if(mode & 1) value = __webpack_require__(value); | |
/******/ if(mode & 8) return value; | |
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | |
/******/ var ns = Object.create(null); | |
/******/ __webpack_require__.r(ns); | |
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | |
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | |
/******/ return ns; | |
/******/ }; | |
/******/ | |
/******/ // getDefaultExport function for compatibility with non-harmony modules | |
/******/ __webpack_require__.n = function(module) { | |
/******/ var getter = module && module.__esModule ? | |
/******/ function getDefault() { return module['default']; } : | |
/******/ function getModuleExports() { return module; }; | |
/******/ __webpack_require__.d(getter, 'a', getter); | |
/******/ return getter; | |
/******/ }; | |
/******/ | |
/******/ // Object.prototype.hasOwnProperty.call | |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | |
/******/ | |
/******/ // __webpack_public_path__ | |
/******/ __webpack_require__.p = ""; | |
/******/ | |
/******/ | |
/******/ // Load entry module and return exports | |
/******/ return __webpack_require__(__webpack_require__.s = "./main.js"); | |
/******/ }) | |
/************************************************************************/ | |
/******/ ({ | |
/***/ "./main.js": | |
/*!*****************!*\ | |
!*** ./main.js ***! | |
\*****************/ | |
/*! exports provided: default */ | |
/***/ (function(module, __webpack_exports__, __webpack_require__) { | |
"use strict"; | |
__webpack_require__.r(__webpack_exports__); | |
/* harmony import */ var https_raw_githubusercontent_com_facebook_regenerator_main_packages_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js */ "https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js"); | |
/* harmony import */ var https_raw_githubusercontent_com_facebook_regenerator_main_packages_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(https_raw_githubusercontent_com_facebook_regenerator_main_packages_runtime_runtime_js__WEBPACK_IMPORTED_MODULE_0__); | |
function 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); } } | |
function _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); }); }; } | |
var timeout = /*#__PURE__*/function () { | |
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(ms) { | |
return regeneratorRuntime.wrap(function _callee$(_context) { | |
while (1) { | |
switch (_context.prev = _context.next) { | |
case 0: | |
return _context.abrupt("return", new Promise(function (resolve, reject) { | |
setTimeout(resolve, ms); | |
})); | |
case 1: | |
case "end": | |
return _context.stop(); | |
} | |
} | |
}, _callee); | |
})); | |
return function timeout(_x) { | |
return _ref.apply(this, arguments); | |
}; | |
}(); | |
/* harmony default export */ __webpack_exports__["default"] = (/*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { | |
var now; | |
return regeneratorRuntime.wrap(function _callee2$(_context2) { | |
while (1) { | |
switch (_context2.prev = _context2.next) { | |
case 0: | |
console.log("start"); | |
now = Date.now(); | |
console.log("before wait"); | |
_context2.next = 5; | |
return timeout(1000); | |
case 5: | |
console.log(Date.now() - now); // returns 1000 | |
console.log("end"); | |
case 7: | |
case "end": | |
return _context2.stop(); | |
} | |
} | |
}, _callee2); | |
}))); | |
/***/ }), | |
/***/ "https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js": | |
/*!**********************************************************************************************************!*\ | |
!*** external "https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js" ***! | |
\**********************************************************************************************************/ | |
/*! no static exports found */ | |
/***/ (function(module, exports) { | |
module.exports = require("https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js"); | |
/***/ }) | |
/******/ }))); | |
//# sourceMappingURL=app.bundle.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "https://raw.githubusercontent.com/facebook/regenerator/main/packages/runtime/runtime.js" | |
const timeout = async (ms)=> { | |
return new Promise((resolve, reject) => { | |
setTimeout(resolve, ms) | |
}) | |
} | |
export default async () => { | |
console.log("start") | |
const now = Date.now() | |
console.log("before wait") | |
await timeout(1000) | |
console.log(Date.now() - now) // returns 1000 | |
console.log("end") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment