Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Scheduler.ts 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Action } from './scheduler/Action';
  2. import { Subscription } from './Subscription';
  3. import { SchedulerLike, SchedulerAction } from './types';
  4. /**
  5. * An execution context and a data structure to order tasks and schedule their
  6. * execution. Provides a notion of (potentially virtual) time, through the
  7. * `now()` getter method.
  8. *
  9. * Each unit of work in a Scheduler is called an `Action`.
  10. *
  11. * ```ts
  12. * class Scheduler {
  13. * now(): number;
  14. * schedule(work, delay?, state?): Subscription;
  15. * }
  16. * ```
  17. *
  18. * @class Scheduler
  19. * @deprecated Scheduler is an internal implementation detail of RxJS, and
  20. * should not be used directly. Rather, create your own class and implement
  21. * {@link SchedulerLike}
  22. */
  23. export class Scheduler implements SchedulerLike {
  24. /**
  25. * Note: the extra arrow function wrapper is to make testing by overriding
  26. * Date.now easier.
  27. * @nocollapse
  28. */
  29. public static now: () => number = () => Date.now();
  30. constructor(private SchedulerAction: typeof Action,
  31. now: () => number = Scheduler.now) {
  32. this.now = now;
  33. }
  34. /**
  35. * A getter method that returns a number representing the current time
  36. * (at the time this function was called) according to the scheduler's own
  37. * internal clock.
  38. * @return {number} A number that represents the current time. May or may not
  39. * have a relation to wall-clock time. May or may not refer to a time unit
  40. * (e.g. milliseconds).
  41. */
  42. public now: () => number;
  43. /**
  44. * Schedules a function, `work`, for execution. May happen at some point in
  45. * the future, according to the `delay` parameter, if specified. May be passed
  46. * some context object, `state`, which will be passed to the `work` function.
  47. *
  48. * The given arguments will be processed an stored as an Action object in a
  49. * queue of actions.
  50. *
  51. * @param {function(state: ?T): ?Subscription} work A function representing a
  52. * task, or some unit of work to be executed by the Scheduler.
  53. * @param {number} [delay] Time to wait before executing the work, where the
  54. * time unit is implicit and defined by the Scheduler itself.
  55. * @param {T} [state] Some contextual data that the `work` function uses when
  56. * called by the Scheduler.
  57. * @return {Subscription} A subscription in order to be able to unsubscribe
  58. * the scheduled work.
  59. */
  60. public schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number = 0, state?: T): Subscription {
  61. return new this.SchedulerAction<T>(this, work).schedule(state, delay);
  62. }
  63. }