File tree Expand file tree Collapse file tree 2 files changed +44
-5
lines changed
main/java/rx/internal/operators
test/java/rx/internal/operators Expand file tree Collapse file tree 2 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -49,22 +49,36 @@ public Subscriber<? super T> call(final Subscriber<? super T> child) {
49
49
final Worker worker = scheduler .createWorker ();
50
50
child .add (worker );
51
51
return new Subscriber <T >(child ) {
52
-
52
+ // indicates an error cut ahead
53
+ // accessed from the worker thread only
54
+ boolean done ;
53
55
@ Override
54
56
public void onCompleted () {
55
57
worker .schedule (new Action0 () {
56
58
57
59
@ Override
58
60
public void call () {
59
- child .onCompleted ();
61
+ if (!done ) {
62
+ done = true ;
63
+ child .onCompleted ();
64
+ }
60
65
}
61
66
62
67
}, delay , unit );
63
68
}
64
69
65
70
@ Override
66
- public void onError (Throwable e ) {
67
- child .onError (e );
71
+ public void onError (final Throwable e ) {
72
+ worker .schedule (new Action0 () {
73
+ @ Override
74
+ public void call () {
75
+ if (!done ) {
76
+ done = true ;
77
+ child .onError (e );
78
+ worker .unsubscribe ();
79
+ }
80
+ }
81
+ });
68
82
}
69
83
70
84
@ Override
@@ -73,7 +87,9 @@ public void onNext(final T t) {
73
87
74
88
@ Override
75
89
public void call () {
76
- child .onNext (t );
90
+ if (!done ) {
91
+ child .onNext (t );
92
+ }
77
93
}
78
94
79
95
}, delay , unit );
Original file line number Diff line number Diff line change @@ -798,4 +798,27 @@ public Integer call(Integer t) {
798
798
ts .assertNoErrors ();
799
799
assertEquals (RxRingBuffer .SIZE * 2 , ts .getOnNextEvents ().size ());
800
800
}
801
+
802
+ @ Test
803
+ public void testErrorRunsBeforeOnNext () {
804
+ TestScheduler test = Schedulers .test ();
805
+
806
+ PublishSubject <Integer > ps = PublishSubject .create ();
807
+
808
+ TestSubscriber <Integer > ts = TestSubscriber .create ();
809
+
810
+ ps .delay (1 , TimeUnit .SECONDS , test ).subscribe (ts );
811
+
812
+ ps .onNext (1 );
813
+
814
+ test .advanceTimeBy (500 , TimeUnit .MILLISECONDS );
815
+
816
+ ps .onError (new TestException ());
817
+
818
+ test .advanceTimeBy (1 , TimeUnit .SECONDS );
819
+
820
+ ts .assertNoValues ();
821
+ ts .assertError (TestException .class );
822
+ ts .assertNotCompleted ();
823
+ }
801
824
}
You can’t perform that action at this time.
0 commit comments