Created
April 20, 2019 16:03
-
-
Save dtothefp/b6700938b53a58a17b9e3fb07585df94 to your computer and use it in GitHub Desktop.
Simple Async Timer Compiled
This file contains hidden or 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 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 wait = function wait() { | |
var duration = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; | |
return new Promise(function (res) { | |
return setTimeout(res, duration); | |
}); | |
}; | |
export default | |
/*#__PURE__*/ | |
_asyncToGenerator( | |
/*#__PURE__*/ | |
regeneratorRuntime.mark(function _callee() { | |
var duration, | |
_args = arguments; | |
return regeneratorRuntime.wrap(function _callee$(_context) { | |
while (1) { | |
switch (_context.prev = _context.next) { | |
case 0: | |
duration = _args.length > 0 && _args[0] !== undefined ? _args[0] : 500; | |
console.log('WAITING', wait); | |
_context.next = 4; | |
return wait(duration); | |
case 4: | |
console.log('DONE'); | |
case 5: | |
case "end": | |
return _context.stop(); | |
} | |
} | |
}, _callee); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment