1384fcc4eab67878b37f53deadb833a365daf8bb85ba5c595f0d833947f5894180334ae561a4572bb6ce079254119d8adf9eccae84c4cd01862846bf4932e7 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import { Immediate } from '../util/Immediate';
  2. import type { TimerHandle } from './timerHandle';
  3. const { setImmediate, clearImmediate } = Immediate;
  4. type SetImmediateFunction = (handler: () => void, ...args: any[]) => TimerHandle;
  5. type ClearImmediateFunction = (handle: TimerHandle) => void;
  6. interface ImmediateProvider {
  7. setImmediate: SetImmediateFunction;
  8. clearImmediate: ClearImmediateFunction;
  9. delegate:
  10. | {
  11. setImmediate: SetImmediateFunction;
  12. clearImmediate: ClearImmediateFunction;
  13. }
  14. | undefined;
  15. }
  16. export const immediateProvider: ImmediateProvider = {
  17. // When accessing the delegate, use the variable rather than `this` so that
  18. // the functions can be called without being bound to the provider.
  19. setImmediate(...args) {
  20. const { delegate } = immediateProvider;
  21. return (delegate?.setImmediate || setImmediate)(...args);
  22. },
  23. clearImmediate(handle) {
  24. const { delegate } = immediateProvider;
  25. return (delegate?.clearImmediate || clearImmediate)(handle as any);
  26. },
  27. delegate: undefined,
  28. };