use of io.reactivex.rxjava3.disposables.CompositeDisposable in project Signal-Android by WhisperSystems.
the class SignalWebSocket method getUnidentifiedWebSocket.
private synchronized WebSocketConnection getUnidentifiedWebSocket() throws WebSocketUnavailableException {
if (!canConnect) {
throw new WebSocketUnavailableException();
}
if (unidentifiedWebSocket == null || unidentifiedWebSocket.isDead()) {
unidentifiedWebSocketStateDisposable.dispose();
unidentifiedWebSocket = webSocketFactory.createUnidentifiedWebSocket();
unidentifiedWebSocketStateDisposable = new CompositeDisposable();
Disposable state = unidentifiedWebSocket.connect().subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).subscribe(unidentifiedWebSocketState::onNext);
unidentifiedWebSocketStateDisposable.add(state);
}
return unidentifiedWebSocket;
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project Signal-Android by WhisperSystems.
the class SignalWebSocket method getWebSocket.
private synchronized WebSocketConnection getWebSocket() throws WebSocketUnavailableException {
if (!canConnect) {
throw new WebSocketUnavailableException();
}
if (webSocket == null || webSocket.isDead()) {
webSocketStateDisposable.dispose();
webSocket = webSocketFactory.createWebSocket();
webSocketStateDisposable = new CompositeDisposable();
Disposable state = webSocket.connect().subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).subscribe(webSocketState::onNext);
webSocketStateDisposable.add(state);
}
return webSocket;
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompositeDisposableTest method exception.
@Test
public void exception() {
final AtomicInteger counter = new AtomicInteger();
CompositeDisposable cd = new CompositeDisposable();
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
throw new RuntimeException("failed on first one");
}
}));
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
}));
try {
cd.dispose();
fail("Expecting an exception");
} catch (RuntimeException e) {
// we expect this
assertEquals(e.getMessage(), "failed on first one");
}
// we should still have disposed to the second one
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompositeDisposableTest method unsubscribeIdempotence.
@Test
public void unsubscribeIdempotence() {
final AtomicInteger counter = new AtomicInteger();
CompositeDisposable cd = new CompositeDisposable();
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
}));
cd.dispose();
cd.dispose();
cd.dispose();
// we should have only disposed once
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompositeDisposableTest method compositeException.
@Test
public void compositeException() {
final AtomicInteger counter = new AtomicInteger();
CompositeDisposable cd = new CompositeDisposable();
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
throw new RuntimeException("failed on first one");
}
}));
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
throw new RuntimeException("failed on second one too");
}
}));
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
}));
try {
cd.dispose();
fail("Expecting an exception");
} catch (CompositeException e) {
// we expect this
assertEquals(e.getExceptions().size(), 2);
}
// we should still have disposed to the second one
assertEquals(1, counter.get());
}
Aggregations