16037b2b575a136d2c4b4a6e6191f5a9125f5276bbff8137b58242a72bd50d1d521d820e2b7901ab41aeccb57c44e248c3f257460eb33cdd49d791989ba58a 949 B

123456789101112131415161718192021222324252627
  1. import { Observable } from '../Observable';
  2. import { SchedulerLike } from '../types';
  3. export function scheduleArray<T>(input: ArrayLike<T>, scheduler: SchedulerLike) {
  4. return new Observable<T>((subscriber) => {
  5. // The current array index.
  6. let i = 0;
  7. // Start iterating over the array like on a schedule.
  8. return scheduler.schedule(function () {
  9. if (i === input.length) {
  10. // If we have hit the end of the array like in the
  11. // previous job, we can complete.
  12. subscriber.complete();
  13. } else {
  14. // Otherwise let's next the value at the current index,
  15. // then increment our index.
  16. subscriber.next(input[i++]);
  17. // If the last emission didn't cause us to close the subscriber
  18. // (via take or some side effect), reschedule the job and we'll
  19. // make another pass.
  20. if (!subscriber.closed) {
  21. this.schedule();
  22. }
  23. }
  24. });
  25. });
  26. }