Sha256: 3a1e36eb05a451508cca7bbea91b10577a8cf8b546c1f5bc6ec5d94dfcfea458

Contents?: true

Size: 1.33 KB

Versions: 49

Compression:

Stored size: 1.33 KB

Contents

import { Operator } from '../Operator';
import { Observable } from '../Observable';
import { Subscriber } from '../Subscriber';
import { IScheduler } from '../Scheduler';
import { async } from '../scheduler/async';
import { OperatorFunction } from '../interfaces';

export function timeInterval<T>(scheduler: IScheduler = async): OperatorFunction<T, TimeInterval<T>> {
  return (source: Observable<T>) => source.lift(new TimeIntervalOperator(scheduler));
}

export class TimeInterval<T> {
  constructor(public value: T, public interval: number) {

  }
};

class TimeIntervalOperator<T> implements Operator<T, TimeInterval<T>> {
  constructor(private scheduler: IScheduler) {

  }

  call(observer: Subscriber<TimeInterval<T>>, source: any): any {
    return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler));
  }
}

/**
 * We need this JSDoc comment for affecting ESDoc.
 * @ignore
 * @extends {Ignored}
 */
class TimeIntervalSubscriber<T> extends Subscriber<T> {
  private lastTime: number = 0;

  constructor(destination: Subscriber<TimeInterval<T>>, private scheduler: IScheduler) {
    super(destination);

    this.lastTime = scheduler.now();
  }

  protected _next(value: T) {
    let now = this.scheduler.now();
    let span = now - this.lastTime;
    this.lastTime = now;

    this.destination.next(new TimeInterval(value, span));
  }
}

Version data entries

49 entries across 49 versions & 4 rubygems

Version Path
govuk_publishing_components-17.8.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.7.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.6.1 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.6.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.5.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.4.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.3.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.2.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.1.1 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.1.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-17.0.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.29.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.28.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.27.1 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.27.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.26.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.25.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.24.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.23.0 node_modules/rxjs/src/operators/timeInterval.ts
govuk_publishing_components-16.22.0 node_modules/rxjs/src/operators/timeInterval.ts