race.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.raceInit = exports.race = void 0;
  4. var Observable_1 = require("../Observable");
  5. var innerFrom_1 = require("./innerFrom");
  6. var argsOrArgArray_1 = require("../util/argsOrArgArray");
  7. var OperatorSubscriber_1 = require("../operators/OperatorSubscriber");
  8. function race() {
  9. var sources = [];
  10. for (var _i = 0; _i < arguments.length; _i++) {
  11. sources[_i] = arguments[_i];
  12. }
  13. sources = argsOrArgArray_1.argsOrArgArray(sources);
  14. return sources.length === 1 ? innerFrom_1.innerFrom(sources[0]) : new Observable_1.Observable(raceInit(sources));
  15. }
  16. exports.race = race;
  17. function raceInit(sources) {
  18. return function (subscriber) {
  19. var subscriptions = [];
  20. var _loop_1 = function (i) {
  21. subscriptions.push(innerFrom_1.innerFrom(sources[i]).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
  22. if (subscriptions) {
  23. for (var s = 0; s < subscriptions.length; s++) {
  24. s !== i && subscriptions[s].unsubscribe();
  25. }
  26. subscriptions = null;
  27. }
  28. subscriber.next(value);
  29. })));
  30. };
  31. for (var i = 0; subscriptions && !subscriber.closed && i < sources.length; i++) {
  32. _loop_1(i);
  33. }
  34. };
  35. }
  36. exports.raceInit = raceInit;
  37. //# sourceMappingURL=race.js.map