createRace.d.ts 719 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Constructs a function that will only invoke the first function passed to it
  3. * concurrently. Once the function has been executed, the racer will be reset
  4. * and the next invocation will be allowed to execute.
  5. *
  6. * Example:
  7. *
  8. * ```ts
  9. * import {createRace} from 'thingies/es2020/createRace';
  10. *
  11. * const race = createRace();
  12. *
  13. * race(() => {
  14. * race(() => {
  15. * console.log('This will not be executed');
  16. * });
  17. * console.log('This will be executed');
  18. * });
  19. *
  20. * race(() => {
  21. * console.log('This will be executed');
  22. * });
  23. * ```
  24. *
  25. * @returns A "race" function that will only invoke the first function passed to it.
  26. */
  27. export declare const createRace: () => <T>(fn: () => T) => T | undefined;