Source

async/wait.js

  1. "use strict";
  2. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  3. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  4. if (ar || !(i in from)) {
  5. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  6. ar[i] = from[i];
  7. }
  8. }
  9. return to.concat(ar || Array.prototype.slice.call(from));
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. /**
  13. * Wait for some time in a promise style (timer)
  14. *
  15. * Reference: https://stackoverflow.com/a/38956190/9428719
  16. *
  17. * @param ms The time in milliseconds to wait
  18. * @param resolveValues The value(s) to resolve
  19. * @category async
  20. * @module wait
  21. */
  22. function wait(ms) {
  23. var resolveValues = [];
  24. for (var _i = 1; _i < arguments.length; _i++) {
  25. resolveValues[_i - 1] = arguments[_i];
  26. }
  27. return new Promise(function (resolve) {
  28. setTimeout.apply(void 0, __spreadArray([resolve, ms], resolveValues, false));
  29. });
  30. }
  31. exports.default = wait;