async.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /** PURE_IMPORTS_START ._AsyncAction,._AsyncScheduler PURE_IMPORTS_END */
  2. import { AsyncAction } from './AsyncAction';
  3. import { AsyncScheduler } from './AsyncScheduler';
  4. /**
  5. *
  6. * Async Scheduler
  7. *
  8. * <span class="informal">Schedule task as if you used setTimeout(task, duration)</span>
  9. *
  10. * `async` scheduler schedules tasks asynchronously, by putting them on the JavaScript
  11. * event loop queue. It is best used to delay tasks in time or to schedule tasks repeating
  12. * in intervals.
  13. *
  14. * If you just want to "defer" task, that is to perform it right after currently
  15. * executing synchronous code ends (commonly achieved by `setTimeout(deferredTask, 0)`),
  16. * better choice will be the {@link asap} scheduler.
  17. *
  18. * @example <caption>Use async scheduler to delay task</caption>
  19. * const task = () => console.log('it works!');
  20. *
  21. * Rx.Scheduler.async.schedule(task, 2000);
  22. *
  23. * // After 2 seconds logs:
  24. * // "it works!"
  25. *
  26. *
  27. * @example <caption>Use async scheduler to repeat task in intervals</caption>
  28. * function task(state) {
  29. * console.log(state);
  30. * this.schedule(state + 1, 1000); // `this` references currently executing Action,
  31. * // which we reschedule with new state and delay
  32. * }
  33. *
  34. * Rx.Scheduler.async.schedule(task, 3000, 0);
  35. *
  36. * // Logs:
  37. * // 0 after 3s
  38. * // 1 after 4s
  39. * // 2 after 5s
  40. * // 3 after 6s
  41. *
  42. * @static true
  43. * @name async
  44. * @owner Scheduler
  45. */
  46. export var async = /*@__PURE__*/ new AsyncScheduler(AsyncAction);
  47. //# sourceMappingURL=async.js.map