asap.js 1.6 KB

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