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