btroncone / learn-rxjs

Clear examples, explanations, and resources for RxJS

Home Page:https://www.learnrxjs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

throttleTime wrong explanation

fridoo opened this issue · comments

It says throttleTime emits the latest value (as if leading: false, trailing: true was used) but throttleTime's default behaviour is to emit the first value.
The example output of example 1 is wrong also.

From https://www.learnrxjs.io/operators/filtering/throttletime.html

Emit latest value when specified duration has passed.

Example 1
last value emitted before throttle ends will be emitted from source

From https://rxjs-dev.firebaseapp.com/api/operators/throttleTime

Emits a value from the source Observable, then ignores subsequent source values for duration milliseconds, then repeats this process.

Lets a value pass, then ignores source values for the next duration milliseconds.

You're absolutely right, my example was wrong. I have updated, thanks for the issue! 👍

Great.
I just noticed that the stackblitz examples produce different outputs for me on Firefox 70 and Chrome 78.

e.g. for example 1:

Firefox and Safari: 0...5...10
Chrome: 0...6...12

It seems to be problematic that interval(1000) emits a value at ~5000 milliseconds and throttleTime(5000) also ends a throttle interval at ~5000 milliseconds. On Firefox and Safari the throttle interval seems to end first leading to 5 being emitted and starting a new throttle interval. On Chrome the interval seems to emit first leading to 5 falling into the first throttle interval and the next one being started 1 second later by 6.

Changing the duration to e.g. throttleInterval(4990), throttleInterval(5010), interval(990) or interval(1010) so that interval and throttleTime aren't in sync makes all browsers emit the same output.

You might want to look into this to prevent confusion.

Good point, I’ll try to update shortly. Thanks again!