Netflix/RxJava — pull request #778 by vadims (2014-01-22 18:51:19+00:00)
Title: Fix zip race condition

The ItemObserver collection logic needs to run in both the OnNext and OnCompleted handlers.

Otherwise, you might have values waiting to be emitted and without seeing an OnCompleted. I couldn't think of an easy unit test for this, it actually took a while to narrow down the example.

The only way I could reproduce it on my machine was to use Hystrix and it happens somewhat sporadically (10-50 iterations).

```java
public class Test {

public static class DummyCommand extends HystrixCommand {

protected DummyCommand() {
super(HystrixCommandGroupKey.Factory.asKey("Dummy"));
}

@Override
protected Integer run() throws Exception {
Thread.sleep(1);
return 1;
}
}

public static void main(String[] args) throws InterruptedException {

while (true) {
Observable.zip(tap(new DummyCommand().observe()), tap(new DummyCommand().observe()), new Func2() {
@Override
public Integer call(Integer a, Integer b) {
return a + b;
}
}).toBlockingObservable().single();
System.out.println("\n\n\n");
Thread.sleep(5);
}

}

public static Observable tap(Observable observable) {
return observable.doOnEach(new Action1>() {
@Override
public void call(Notification notification) {
System.out.println("notification = " + notification);
}
});
}

}
```