Skip to content

Commit

Permalink
Fixed duplicate initiation calls to the device manager.
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Oct 4, 2017
1 parent 8be178b commit 717ff15
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class DeviceManager {
private BluetoothSource bluetoothSource;
private final StreamHelper streamHelper;
private final BehaviorSubject<Map<String, ManagedDevice>> deviceObs = BehaviorSubject.create();
private volatile boolean initial = true;

@Inject
public DeviceManager(BluetoothSource bluetoothSource, StreamHelper streamHelper) {
Expand All @@ -42,10 +43,13 @@ private Realm getRealm() {

@NonNull
public Observable<Map<String, ManagedDevice>> observe() {
if (deviceObs.getValue() == null) {
Observable.defer(() -> loadDevices(true).toObservable())
.subscribeOn(Schedulers.computation())
.subscribe();
synchronized (this) {
if (deviceObs.getValue() == null && initial) {
initial = false;
Observable.defer(() -> loadDevices(true).toObservable())
.subscribeOn(Schedulers.computation())
.subscribe();
}
}
return deviceObs;
}
Expand Down

0 comments on commit 717ff15

Please sign in to comment.