io.reactivex.subjects.CompletableSubject Java Examples

The following examples show how to use io.reactivex.subjects.CompletableSubject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThrottledLollipopScanner.java    From RxCentralBle with Apache License 2.0 6 votes vote down vote up
public ThrottledLollipopScanner(ParsedAdvertisement.Factory parsedAdDataFactory,
                                long maxScanDurationMs,
                                long pauseIntervalMs) {
  this.parsedAdDataFactory = parsedAdDataFactory;
  this.scanCallback = getScanCallback();
  this.maxScanDurationMs = maxScanDurationMs;
  this.pauseIntervalMs = pauseIntervalMs;

  this.errorSubject = CompletableSubject.create();
  this.sharedScanData = scanModeRelay
          .switchMap(nextScanMode -> Observable.fromCallable(this::calculateDelay)
                  .switchMap(delay -> Observable.timer(delay, TimeUnit.MILLISECONDS))
                  .map(proceed -> nextScanMode))
          .distinctUntilChanged()
          .switchMap(nextScanMode -> Observable.concat(
                  // Start a (potentially delayed) throttled scan.
                  throttledScan(scanDataRelay, nextScanMode),
                  // Repeat pause followed by throttle scan.
                  intervalScan(scanDataRelay, nextScanMode)))
          .doFinally(this::cleanup)
          .share();
}
 
Example #2
Source File: TestMockitoCalls.java    From akarnokd-misc with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    @SuppressWarnings("unchecked")
    List<Integer> list = mock(List.class);
    
    CompletableSubject source = CompletableSubject.create();
    
    source.doOnSubscribe(v -> list.add(1))
    .doOnError(e -> list.remove(1))
    .doOnComplete(() -> list.remove(1))
    .subscribe();
    
    source.onComplete();
    
    verify(list).add(1);
    verify(list).remove(1);
    verifyNoMoreInteractions(list);
}
 
Example #3
Source File: JellyBeanScanner.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
public JellyBeanScanner(ParsedAdvertisement.Factory parsedAdDataFactory) {
  this.parsedAdDataFactory = parsedAdDataFactory;
  this.leScanCallback = getScanCallback();

  this.errorSubject = CompletableSubject.create();
  this.sharedScanData = scanDataRelay
          .doOnSubscribe(disposable -> startScan())
          .doFinally(this::stopScan)
          .share();
}
 
Example #4
Source File: JellyBeanScanner.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
private CompletableSubject getErrorSubject() {
  synchronized (syncRoot) {
    if (errorSubject.hasThrowable()) {
      errorSubject = CompletableSubject.create();
    }

    return errorSubject;
  }
}
 
Example #5
Source File: ThrottledLollipopScanner.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
private CompletableSubject getErrorSubject() {
  synchronized (syncRoot) {
    if (errorSubject.hasThrowable()) {
      errorSubject = CompletableSubject.create();
    }

    return errorSubject;
  }
}