-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
A bug using .seconds
in throttle
.
#2098
Comments
.seconds
in throttle
..seconds
in throttle
.
Hi @danielt1263, your code doesn't prove that we have a bug. It seems to me that you have defined a race in your code between There is no guarantee regarding timing in these cases. We are relying on the underlying dispatch queue behavior mostly. If you think that something can be improved, you are welcome to make a PR so we can discuss your proposal, but if you presented this code to someone without "works" and "doesn't work" nobody could tell you what is expected from that code IMHO. |
Hey @danielt1263 — would appreciate your comment on this thread, if you could provide a more practical and non-theoretical example. We unfortunately can't control GCD and its relation to DispatchTime, but this is still interesting if you have more content to share. |
-- Edit: The last paragraph is actually the most important if you want to skip to that. Sure. In the actual code where I discovered the issue, the first It's surprising to me that two events can come through with a full half-second delay between them and throttle(.seconds(1)) doesn't throttle the latter event (whereas throttle(.milliseconds(1000)) does. I get that you can't control exactly when events are scheduled in relation to each other, but for the throttle to miss a full half-second delay is odd isn't it? Note that given the following:
I'm getting output of:
The first event enters Note that if you set the delay to 400 milliseconds, then it does throttle the event, but it fails to throttle if the delay is at 500 milliseconds or greater. I get the impression that there is some sort of integer division going on when there shouldn't be. |
I'm closing every issue older than 6 months. If this is still an issue for you, please comment and I can reopen :) Thanks ! |
我觉得这里是有点问题,主要在代码的这个位置
这里是对比 上一次触发的时间 和 当前的时间,如果计算后最后返回值是0,那么就触发一次。 |
@freak4pc RxSwift/RxSwift/Date+Dispatch.swift Lines 43 to 50 in 65bec4c
For example, if .second(1) is set in the code below, a quick consecutive tap may cause events to occur in 0.5 second increments for the above reason.
button.rx.tap.throttle(.seconds(1), scheduler: MainScheduler.instance) This is probably not the intended behavior in many cases, so it might be better to describe this in the documentation or something. Please consider this if you would like. |
Okay, so the I think we can leave this closed, but it would be nice to document somewhere... |
Short description of the issue:
I found a
throttle
bug.Expected outcome:
Each of the two observable chains above should emit a single next event.
What actually happens:
The "Doesn't Work" chain emits two events.
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
5.0.0
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
Installation method:
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
The text was updated successfully, but these errors were encountered: