Scheduler.d.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 declare class Scheduler implements SchedulerLike {
  24. private SchedulerAction;
  25. /**
  26. * Note: the extra arrow function wrapper is to make testing by overriding
  27. * Date.now easier.
  28. * @nocollapse
  29. */
  30. static now: () => number;
  31. constructor(SchedulerAction: typeof Action, now?: () => number);
  32. /**
  33. * A getter method that returns a number representing the current time
  34. * (at the time this function was called) according to the scheduler's own
  35. * internal clock.
  36. * @return {number} A number that represents the current time. May or may not
  37. * have a relation to wall-clock time. May or may not refer to a time unit
  38. * (e.g. milliseconds).
  39. */
  40. now: () => number;
  41. /**
  42. * Schedules a function, `work`, for execution. May happen at some point in
  43. * the future, according to the `delay` parameter, if specified. May be passed
  44. * some context object, `state`, which will be passed to the `work` function.
  45. *
  46. * The given arguments will be processed an stored as an Action object in a
  47. * queue of actions.
  48. *
  49. * @param {function(state: ?T): ?Subscription} work A function representing a
  50. * task, or some unit of work to be executed by the Scheduler.
  51. * @param {number} [delay] Time to wait before executing the work, where the
  52. * time unit is implicit and defined by the Scheduler itself.
  53. * @param {T} [state] Some contextual data that the `work` function uses when
  54. * called by the Scheduler.
  55. * @return {Subscription} A subscription in order to be able to unsubscribe
  56. * the scheduled work.
  57. */
  58. schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay?: number, state?: T): Subscription;
  59. }