PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
src
/
internal
/
operators
import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { empty } from '../observable/empty'; import { MonoTypeOperatorFunction, TeardownLogic } from '../types'; /** * Returns an Observable that will resubscribe to the source stream when the source stream completes, at most count times. * * <span class="informal">Repeats all values emitted on the source. It's like {@link retry}, but for non error cases.</span> * *  * * Similar to {@link retry}, this operator repeats the stream of items emitted by the source for non error cases. * Repeat can be useful for creating observables that are meant to have some repeated pattern or rhythm. * * Note: `repeat(0)` returns an empty observable and `repeat()` will repeat forever * * ## Example * Repeat a message stream * ```ts * import { of } from 'rxjs'; * import { repeat, delay } from 'rxjs/operators'; * * const source = of('Repeat message'); * const example = source.pipe(repeat(3)); * example.subscribe(x => console.log(x)); * * // Results * // Repeat message * // Repeat message * // Repeat message * ``` * * Repeat 3 values, 2 times * ```ts * import { interval } from 'rxjs'; * import { repeat, take } from 'rxjs/operators'; * * const source = interval(1000); * const example = source.pipe(take(3), repeat(2)); * example.subscribe(x => console.log(x)); * * // Results every second * // 0 * // 1 * // 2 * // 0 * // 1 * // 2 * ``` * * @see {@link repeatWhen} * @see {@link retry} * * @param {number} [count] The number of times the source Observable items are repeated, a count of 0 will yield * an empty Observable. * @return {Observable} An Observable that will resubscribe to the source stream when the source stream completes * , at most count times. * @method repeat * @owner Observable */ export function repeat<T>(count: number = -1): MonoTypeOperatorFunction<T> { return (source: Observable<T>) => { if (count === 0) { return empty(); } else if (count < 0) { return source.lift(new RepeatOperator(-1, source)); } else { return source.lift(new RepeatOperator(count - 1, source)); } }; } class RepeatOperator<T> implements Operator<T, T> { constructor(private count: number, private source: Observable<T>) { } call(subscriber: Subscriber<T>, source: any): TeardownLogic { return source.subscribe(new RepeatSubscriber(subscriber, this.count, this.source)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class RepeatSubscriber<T> extends Subscriber<T> { constructor(destination: Subscriber<any>, private count: number, private source: Observable<T>) { super(destination); } complete() { if (!this.isStopped) { const { source, count } = this; if (count === 0) { return super.complete(); } else if (count > -1) { this.count = count - 1; } source.subscribe(this._unsubscribeAndRecycle()); } } }
[-] toArray.ts
[edit]
[-] window.ts
[edit]
[-] retry.ts
[edit]
[-] mergeAll.ts
[edit]
[-] windowWhen.ts
[edit]
[-] every.ts
[edit]
[-] timeout.ts
[edit]
[-] debounceTime.ts
[edit]
[-] index.ts
[edit]
[-] takeWhile.ts
[edit]
[-] audit.ts
[edit]
[-] reduce.ts
[edit]
[-] mapTo.ts
[edit]
[-] count.ts
[edit]
[-] debounce.ts
[edit]
[-] throwIfEmpty.ts
[edit]
[-] auditTime.ts
[edit]
[-] scan.ts
[edit]
[-] switchAll.ts
[edit]
[-] map.ts
[edit]
[-] bufferCount.ts
[edit]
[-] mergeScan.ts
[edit]
[-] publish.ts
[edit]
[-] min.ts
[edit]
[+]
..
[-] publishReplay.ts
[edit]
[-] bufferTime.ts
[edit]
[-] share.ts
[edit]
[-] repeat.ts
[edit]
[-] distinct.ts
[edit]
[-] concatMapTo.ts
[edit]
[-] buffer.ts
[edit]
[-] concatMap.ts
[edit]
[-] max.ts
[edit]
[-] partition.ts
[edit]
[-] observeOn.ts
[edit]
[-] bufferWhen.ts
[edit]
[-] dematerialize.ts
[edit]
[-] throttle.ts
[edit]
[-] groupBy.ts
[edit]
[-] withLatestFrom.ts
[edit]
[-] exhaust.ts
[edit]
[-] exhaustMap.ts
[edit]
[-] retryWhen.ts
[edit]
[-] zipAll.ts
[edit]
[-] find.ts
[edit]
[-] mergeMap.ts
[edit]
[-] single.ts
[edit]
[-] last.ts
[edit]
[-] combineLatest.ts
[edit]
[-] publishLast.ts
[edit]
[-] pluck.ts
[edit]
[-] pairwise.ts
[edit]
[-] distinctUntilChanged.ts
[edit]
[-] timeInterval.ts
[edit]
[-] shareReplay.ts
[edit]
[-] skipUntil.ts
[edit]
[-] findIndex.ts
[edit]
[-] windowToggle.ts
[edit]
[-] startWith.ts
[edit]
[-] timeoutWith.ts
[edit]
[-] concat.ts
[edit]
[-] materialize.ts
[edit]
[-] timestamp.ts
[edit]
[-] onErrorResumeNext.ts
[edit]
[-] subscribeOn.ts
[edit]
[-] takeUntil.ts
[edit]
[-] skipLast.ts
[edit]
[-] throttleTime.ts
[edit]
[-] mergeMapTo.ts
[edit]
[-] multicast.ts
[edit]
[-] merge.ts
[edit]
[-] takeLast.ts
[edit]
[-] delayWhen.ts
[edit]
[-] sampleTime.ts
[edit]
[-] tap.ts
[edit]
[-] take.ts
[edit]
[-] sample.ts
[edit]
[-] filter.ts
[edit]
[-] skip.ts
[edit]
[-] expand.ts
[edit]
[-] publishBehavior.ts
[edit]
[-] sequenceEqual.ts
[edit]
[-] ignoreElements.ts
[edit]
[-] catchError.ts
[edit]
[-] endWith.ts
[edit]
[-] refCount.ts
[edit]
[-] windowCount.ts
[edit]
[-] defaultIfEmpty.ts
[edit]
[-] windowTime.ts
[edit]
[-] switchMapTo.ts
[edit]
[-] switchMap.ts
[edit]
[-] delay.ts
[edit]
[-] bufferToggle.ts
[edit]
[-] repeatWhen.ts
[edit]
[-] concatAll.ts
[edit]
[-] first.ts
[edit]
[-] zip.ts
[edit]
[-] elementAt.ts
[edit]
[-] skipWhile.ts
[edit]
[-] race.ts
[edit]
[-] finalize.ts
[edit]
[-] combineAll.ts
[edit]
[-] distinctUntilKeyChanged.ts
[edit]
[-] isEmpty.ts
[edit]