Hi!
I was watching the video of this code base and saw a common mistake in using Subjects:
|
private BehaviorSubject<Battle> battleSubject = BehaviorSubject.create(); |
Subjects by default are not thread safe when calling onNext and lines 34:
|
.delay(EMIT_RATE_SECONDS / 2, TimeUnit.SECONDS) |
|
.subscribe(battle -> battleSubject.onNext(battle)); |
and 46:
|
|
|
observable.subscribe(battle -> battleSubject.onNext(battle)); |
may end up calling it concurrently, which leads to undefined behavior.
Line 26 should look like this instead:
private Subject<Battle> battleSubject = BehaviorSubject.<Battle>create().toSerialized();
Hi!
I was watching the video of this code base and saw a common mistake in using
Subjects:RxJavaGoT/app/src/main/java/net/tensory/rxjavatalk/repositories/BattleFrontFeed.java
Line 26 in 110c3a2
Subjects by default are not thread safe when callingonNextand lines 34:RxJavaGoT/app/src/main/java/net/tensory/rxjavatalk/repositories/BattleFrontFeed.java
Lines 33 to 34 in 110c3a2
and 46:
RxJavaGoT/app/src/main/java/net/tensory/rxjavatalk/repositories/BattleFrontFeed.java
Lines 45 to 46 in 110c3a2
may end up calling it concurrently, which leads to undefined behavior.
Line 26 should look like this instead: