Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throttleTime does not emit last value #3351

Closed
ronag opened this issue Feb 27, 2018 · 5 comments · Fixed by #3559
Closed

throttleTime does not emit last value #3351

ronag opened this issue Feb 27, 2018 · 5 comments · Fixed by #3559

Comments

@ronag
Copy link

ronag commented Feb 27, 2018

throttleTime does not have a _complete handler which means that even if we specify trailing: true we might not get the last value of the stream.

Not sure if this is intentional, but it seems rather unintuitive. Also looking at the spec test the end of stream scenario isn't really defined so it's difficult to tell how it should work.

@ronag ronag changed the title throttleTime does not emit last value if complete throttleTime does not emit last value Feb 27, 2018
@dengwanc
Copy link

dengwanc commented Mar 6, 2018

could you provide more details and reproductions steps ?

@deadbeef84
Copy link

Observable.timer(1000)
  .throttleTime(500, undefined, { trailing: true })
  .subscribe(x => console.log('value', x), undefined, () => console.log('complete'))
// completes without value

I.e. if the source observable completes, the "current" throttled value will get lost.

@benlesh
Copy link
Member

benlesh commented Mar 15, 2018

We need a reproduction please. :)

@yozo1984
Copy link
Contributor

Unlike auditTime, I feel throttleTime is mostly used to limit the number of calls to a certain function or of emissions of values. With the current implementation, the last value can be lost if the observable completes before the throttle time is up.

I feel the last throttle value should be emitted right away in this case but can also be persuade that the we should wait until the throttleTime to emit.

e.g.

const e1 =   hot('-a-xy-----b--x--cxx| ');
const e1subs =   '^                   !';
const t =   time('----|                ');
const expected = '-----y--------x-----(x|)';

benlesh pushed a commit that referenced this issue Apr 13, 2018
…ue (#3559)

Treat complete as a trailing edge and emit the last throttled value when complete before the throttle time is up.

closes #3351
@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants