take.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Emits only the first `count` values emitted by the source Observable.
  6. *
  7. * <span class="informal">Takes the first `count` values from the source, then
  8. * completes.</span>
  9. *
  10. * <img src="./img/take.png" width="100%">
  11. *
  12. * `take` returns an Observable that emits only the first `count` values emitted
  13. * by the source Observable. If the source emits fewer than `count` values then
  14. * all of its values are emitted. After that, it completes, regardless if the
  15. * source completes.
  16. *
  17. * @example <caption>Take the first 5 seconds of an infinite 1-second interval Observable</caption>
  18. * var interval = Rx.Observable.interval(1000);
  19. * var five = interval.take(5);
  20. * five.subscribe(x => console.log(x));
  21. *
  22. * @see {@link takeLast}
  23. * @see {@link takeUntil}
  24. * @see {@link takeWhile}
  25. * @see {@link skip}
  26. *
  27. * @throws {ArgumentOutOfRangeError} When using `take(i)`, it delivers an
  28. * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
  29. *
  30. * @param {number} count The maximum number of `next` values to emit.
  31. * @return {Observable<T>} An Observable that emits only the first `count`
  32. * values emitted by the source Observable, or all of the values from the source
  33. * if the source emits fewer than `count` values.
  34. * @method take
  35. * @owner Observable
  36. */
  37. function take(count) {
  38. return operators_1.take(count)(this);
  39. }
  40. exports.take = take;
  41. //# sourceMappingURL=take.js.map