-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Optimize OperatorSkipLastTimed #1065
Conversation
RxJava-pull-requests #981 SUCCESS |
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
buffer = Collections.emptyList(); | ||
subscriber.onError(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need to call emitItemsOutOfWindow
in onError
. Which one is more reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm doing buffer now and they all emit buffered data in case of onError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in Rx.Net.
var o = Observable.Create<int>(observer => {
observer.OnNext(2);
Thread.Sleep(2000);
observer.OnError(new Exception("test"));
return Disposable.Empty;
});
o.SkipLast(TimeSpan.FromMilliseconds(100)).ObserveOn(Scheduler.NewThread).Subscribe(
next=>Console.WriteLine(next),
e => Console.WriteLine(e),
() => Console.WriteLine("onCompleted")
);
Console.ReadLine();
The above codes only output
System.Exception: test
So Rx.Net only emits onError
and drops the buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When onError
occurs it immediately emits and does not work any further work.
We had this discussion a while back when debating delay
I think.
Rx Design Guideline 6.6
6.6. OnError messages should have abort semantics
As normal control flow in .NET uses abort semantics for exceptions (the stack is unwound, current code path is interrupted), Rx mimics this behavior. To ensure this behavior, no messages should be sent out by an operator once one of it sources has an error message or an exception is thrown within the operator.
...
In this sample, a buffering operator will abandon the observable sequence as soon as the subscription to source encounters an error. The current buffer is not sent to any subscribers, maintain abort semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarification. Then this PR should be ready to merge.
Optimize OperatorSkipLastTimed
Changed OperatorSkipLastTimed to only cache the latest items in the specified time window.