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.

ConnectionManager.js 1.5KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. class ConnectionManager {
  13. constructor() {
  14. this.promisesAwaitingConnection = [];
  15. }
  16. resolveAllAwaiting() {
  17. this.promisesAwaitingConnection.map(({ resolve }) => resolve());
  18. this.promisesAwaitingConnection = [];
  19. }
  20. rejectAllAwaiting(error) {
  21. this.promisesAwaitingConnection.map(({ reject }) => reject(error));
  22. this.promisesAwaitingConnection = [];
  23. }
  24. awaitConnection() {
  25. return __awaiter(this, void 0, void 0, function* () {
  26. return new Promise((resolve, reject) => {
  27. this.promisesAwaitingConnection.push({ resolve, reject });
  28. });
  29. });
  30. }
  31. }
  32. exports.default = ConnectionManager;
  33. //# sourceMappingURL=ConnectionManager.js.map