`repeat`ed `scheduled` on `animationFrameScheduler` runs request twice
gizm0bill opened this issue · 3 comments
Describe the bug
trying this:
scheduled([0], animationFrameScheduler).pipe( repeat() )
runs at 30fps, meaning the requestAnimationFrame
is called twice (tested)
whilst this:
interval(0, animationFrameScheduler)
runs at 60fps
You can notice this behavior here: https://stackblitz.com/edit/rxjs-aksefi?file=index.ts and the corresponding question that raised this bug, here: https://stackoverflow.com/questions/75781770/rxjs-animationframescheduler-is-triggered-only-every-35ms
Is this a bug or by design?
Expected behavior
let last = performance.now();
scheduled([0], animationFrameScheduler).pipe(
repeat(),
tap(() => {
const performanceNow = performance.now();
console.log(performanceNow - last);
last = performance.now();
}) )
would expect to print values ~= 16
Reproduction URL
https://stackblitz.com/edit/rxjs-aksefi?file=index.ts
Version
7.8.0
not sure if this is a bug, but with the current implementation this behavior is expected (or at least it can be explained):
https://github.com/ReactiveX/rxjs/blob/master/src/internal/scheduled/scheduleArray.ts
For each animationFrame is looks at one index of the array. so at the first animationFrame it emits an item and at the second animationFrame it closes the Observable because there are no more items to emit. here repeat
subscribes again so the emit happens at the third animationFrame
Closing as per OP's comment.