-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
| private BehaviorSubject<Battle> battleSubject = BehaviorSubject.create(); |
Subjects by default are not thread safe when calling onNext and lines 34:
RxJavaGoT/app/src/main/java/net/tensory/rxjavatalk/repositories/BattleFrontFeed.java
Lines 33 to 34 in 110c3a2
| .delay(EMIT_RATE_SECONDS / 2, TimeUnit.SECONDS) | |
| .subscribe(battle -> battleSubject.onNext(battle)); |
and 46:
RxJavaGoT/app/src/main/java/net/tensory/rxjavatalk/repositories/BattleFrontFeed.java
Lines 45 to 46 in 110c3a2
| 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(); thebatu
Metadata
Metadata
Assignees
Labels
No labels