TimedState.d.ts 778 B

1234567891011121314151617181920212223242526
  1. /**
  2. * TimedState works similar to TimedQueue, but instead of saving
  3. * a list of all items pushed, it reduces the state on each push.
  4. */
  5. export declare class TimedState<S, I> {
  6. protected readonly initState: () => S;
  7. protected readonly reducer: (state: S, item: I) => S;
  8. /**
  9. * State will be flushed when it reaches this number of items.
  10. */
  11. itemLimit: number;
  12. /**
  13. * State will be flushed after this many milliseconds.
  14. */
  15. timeLimit: number;
  16. /**
  17. * Method that will be called when state is flushed.
  18. */
  19. onFlush: (state: S) => void;
  20. constructor(initState: () => S, reducer: (state: S, item: I) => S);
  21. protected length: number;
  22. protected state: S;
  23. private timer;
  24. push(item: I): void;
  25. flush(): S;
  26. }