-
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
Fixed testOnErrorViaHasNext in issue #383 #433
Conversation
RxJava-pull-requests #344 SUCCESS |
RxJava-pull-requests #346 SUCCESS |
Regarding |
I think it's better to resolve here. I'll work on it. |
Thanks. |
Thanks for fixing this. Not sure I understand why |
@petermd I suppose that for an iterator, |
I know it seems a little counter-intuitive but that seems to be what the wiki says
|
RxJava-pull-requests #356 FAILURE |
I updated the Now the |
RxJava-pull-requests #358 FAILURE |
What is the weirdness? Sent from my iPad
|
Sorry, I misunderstood about Rx.Net. I removed my related discussion to avoid confusing somebody. |
|
||
@Override | ||
public T next() { | ||
return next; |
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.
Is there ever a time when someone could call next()
in a loop without hasNext()
I don't think it's illegal for someone to do that until it throws a NoSuchElementException
thus we need to do the same blocking logic here in case someone doesn't use hasNext()
http://docs.oracle.com/javase/6/docs/api/java/util/Iterator.html#next()
I updated the PR to follow the iterator contract. Thanks for your review, @benjchristensen |
RxJava-pull-requests #368 FAILURE |
still wondering why this implementation runs contrary to the wiki. that said, i can't find any other implementation of Next operator so can't be 100% sure?
if the perhaps worth noting that this is meant to be a sampler (it does not buffer) so running while(it.hasNext()) {
it.next();
} is not guaranteed to iterate over the output of the does storing the unconsumed |
It's possible to implement it following the wiki. But the wiki is against the Iterator contract in Java. I suppose it's better to follow the Iterator contract so that Java users may feel conformable. Since |
the problem is without buffering the full I think the real issue is, there isn't a good example of how you would use this operator. The name "next" suggests you use it to get an |
As the main wiki writer, I should note that I'm attempting to be On Wed, Oct 23, 2013 at 7:50 AM, Peter McDonnell
David M. Gross |
I think this behavior is very strange. Actually, I tried the IObservable<int> ob =
Observable.Create<int>(o =>
{
Console.WriteLine("Subscribed: Before onNext");
Thread.Sleep(2000);
o.OnNext(1);
Console.WriteLine("Subscribed: After OnNext");
o.OnCompleted();
return Disposable.Empty;
}
);
var iter = ob.SubscribeOn(Scheduler.NewThread).Next().GetEnumerator();
Console.WriteLine("Before MoveNext");
while (iter.MoveNext())
{
Console.WriteLine("Find a value");
Thread.Sleep(5000);
Console.WriteLine("Got " + iter.Current);
}
Console.ReadLine();
} output: Before MoveNext Subscribed: Before onNext Subscribed: After OnNext Find a value Got 1 In this case, Rx.Net also blocks in So I think my current implementation is same as Rx.Net. And we need to update the wiki. |
@DavidMGross - thanks for the clarification. @zsxwing - is the semantic of Enumerable not slightly different (it consists of a hasNext() and next() in the same call)? I don't have a .NET setup to test easily but would be curious about what the output is if you
I'll stop bugging you about it then :-) |
Test case: IObservable<int> ob =
Observable.Create<int>(o =>
{
Console.WriteLine("Subscribed: Before OnCompleted");
Thread.Sleep(2000);
o.OnCompleted();
Console.WriteLine("Subscribed: After OnCompleted");
return Disposable.Empty;
}
);
var iter = ob.SubscribeOn(Scheduler.NewThread).Next().GetEnumerator();
Console.WriteLine("Before MoveNext");
while (iter.MoveNext())
{
Console.WriteLine("Find a value");
Thread.Sleep(5000);
Console.WriteLine("Got " + iter.Current);
}
Console.WriteLine("After MoveNext");
Console.ReadLine(); Output: Before MoveNext Subscribed: Before OnCompleted Subscribed: After OnCompleted After MoveNext
Test case: IObservable<int> ob =
Observable.Create<int>(o =>
{
Console.WriteLine("Subscribed: Before onNext");
Thread.Sleep(2000);
o.OnNext(1);
Console.WriteLine("Subscribed: After OnNext");
o.OnCompleted();
return Disposable.Empty;
}
);
var iter = ob.SubscribeOn(Scheduler.NewThread).Next().GetEnumerator();
Thread.Sleep(5000);
Console.WriteLine("Before MoveNext");
while (iter.MoveNext())
{
Console.WriteLine("Find a value");
Thread.Sleep(5000);
Console.WriteLine("Got " + iter.Current);
}
Console.WriteLine("After MoveNext");
Console.ReadLine(); Output: Subscribed: Before onNext Subscribed: After OnNext Before MoveNext After MoveNext |
These behaviors are consistent with my thought. |
Thanks @zsxwing - so maybe the correct wiki def should be something like? The If the If the |
In my codes, if the Observable emits an error then Iterator.hasNext() and Iterator.next() will both re-throw the exception. However, you remind me that I should always throw the exception for the following |
I updated the PR to let |
RxJava-pull-requests #373 FAILURE |
Let me conclude the
|
That is the protocol for integrators in .net. You have to call movenext, and then current.http://msdn.microsoft.com/en-us/library/vstudio/system.collections.ienumerator.aspx I always assumed that this was the same in java, but the Scala folks told me that typically has next does not block, but calling next does. Which in Scala means you use or not use parens. Not sure if that is true in general. It does make iterators hard to implement. In PHP the protocol is also a bit different where you start with rewind, which is typically ignored in .net. Sent from my iPad
|
@headinthebox javacoc and scaladoc do not say how to block. So I think it should be OK that we block |
Fixed testOnErrorViaHasNext in issue #383
Your explanation of how it works sounds correct, merging. |
Fixed testOnErrorViaHasNext in issue ReactiveX#383
… to close a bulkhead fully. (ReactiveX#433)
Hi,
This PR fixed the issue that
testOnErrorViaHasNext
fails sometimes. It only tries to avoid the failure of unit tests.However, there is still an issue in the
next
operator. ThehasNext
may return true, but the laternext
throwsIllegalStateException("Observable is completed")
. An example unit test throwsIllegalStateException
:I think @abersnaze is right.