Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

waitUntil.js 1.2KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const Timer_1 = __importDefault(require("../../utils/Timer"));
  7. function waitUntil(condition, { timeout = this.options.waitforTimeout, interval = this.options.waitforInterval, timeoutMsg } = {}) {
  8. if (typeof condition !== 'function') {
  9. throw new Error('Condition is not a function');
  10. }
  11. if (typeof timeout !== 'number') {
  12. timeout = this.options.waitforTimeout;
  13. }
  14. if (typeof interval !== 'number') {
  15. interval = this.options.waitforInterval;
  16. }
  17. const fn = condition.bind(this);
  18. let timer = new Timer_1.default(interval, timeout, fn, true);
  19. return timer.catch((e) => {
  20. if (e.message === 'timeout') {
  21. if (typeof timeoutMsg === 'string') {
  22. throw new Error(timeoutMsg);
  23. }
  24. throw new Error(`waitUntil condition timed out after ${timeout}ms`);
  25. }
  26. throw new Error(`waitUntil condition failed with the following reason: ${(e && e.message) || e}`);
  27. });
  28. }
  29. exports.default = waitUntil;