0108b3f03c53401d50107333414c7a57a79c97b82353b28ca3f34b2f41a96930f243cb4954517f39b2bccead059af21afc283283d2916546e3976d9844d0bf 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { AsapAction } from './AsapAction';
  2. import { AsapScheduler } from './AsapScheduler';
  3. /**
  4. *
  5. * Asap Scheduler
  6. *
  7. * <span class="informal">Perform task as fast as it can be performed asynchronously</span>
  8. *
  9. * `asap` scheduler behaves the same as {@link asyncScheduler} scheduler when you use it to delay task
  10. * in time. If however you set delay to `0`, `asap` will wait for current synchronously executing
  11. * code to end and then it will try to execute given task as fast as possible.
  12. *
  13. * `asap` scheduler will do its best to minimize time between end of currently executing code
  14. * and start of scheduled task. This makes it best candidate for performing so called "deferring".
  15. * Traditionally this was achieved by calling `setTimeout(deferredTask, 0)`, but that technique involves
  16. * some (although minimal) unwanted delay.
  17. *
  18. * Note that using `asap` scheduler does not necessarily mean that your task will be first to process
  19. * after currently executing code. In particular, if some task was also scheduled with `asap` before,
  20. * that task will execute first. That being said, if you need to schedule task asynchronously, but
  21. * as soon as possible, `asap` scheduler is your best bet.
  22. *
  23. * ## Example
  24. * Compare async and asap scheduler<
  25. * ```ts
  26. * import { asapScheduler, asyncScheduler } from 'rxjs';
  27. *
  28. * asyncScheduler.schedule(() => console.log('async')); // scheduling 'async' first...
  29. * asapScheduler.schedule(() => console.log('asap'));
  30. *
  31. * // Logs:
  32. * // "asap"
  33. * // "async"
  34. * // ... but 'asap' goes first!
  35. * ```
  36. */
  37. export const asapScheduler = new AsapScheduler(AsapAction);
  38. /**
  39. * @deprecated Renamed to {@link asapScheduler}. Will be removed in v8.
  40. */
  41. export const asap = asapScheduler;