timeInterval.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { SchedulerLike, OperatorFunction } from '../types';
  2. /**
  3. *
  4. * Emits an object containing the current value, and the time that has
  5. * passed between emitting the current value and the previous value, which is
  6. * calculated by using the provided `scheduler`'s `now()` method to retrieve
  7. * the current time at each emission, then calculating the difference. The `scheduler`
  8. * defaults to {@link asyncScheduler}, so by default, the `interval` will be in
  9. * milliseconds.
  10. *
  11. *
  12. * ![](timeinterval.png)
  13. *
  14. * ## Examples
  15. * Emit inteval between current value with the last value
  16. *
  17. * ```ts
  18. * const seconds = interval(1000);
  19. *
  20. * seconds.pipe(timeinterval())
  21. * .subscribe(
  22. * value => console.log(value),
  23. * err => console.log(err),
  24. * );
  25. *
  26. * seconds.pipe(timeout(900))
  27. * .subscribe(
  28. * value => console.log(value),
  29. * err => console.log(err),
  30. * );
  31. *
  32. * // NOTE: The values will never be this precise,
  33. * // intervals created with `interval` or `setInterval`
  34. * // are non-deterministic.
  35. *
  36. * // {value: 0, interval: 1000}
  37. * // {value: 1, interval: 1000}
  38. * // {value: 2, interval: 1000}
  39. * ```
  40. *
  41. * @param {SchedulerLike} [scheduler] Scheduler used to get the current time.
  42. * @return {Observable<{ interval: number, value: T }>} Observable that emit infomation about value and interval
  43. * @method timeInterval
  44. */
  45. export declare function timeInterval<T>(scheduler?: SchedulerLike): OperatorFunction<T, TimeInterval<T>>;
  46. /**
  47. * @deprecated exposed API, use as interface only.
  48. */
  49. export declare class TimeInterval<T> {
  50. value: T;
  51. interval: number;
  52. constructor(value: T, interval: number);
  53. }