rx.functions.Actions Java Examples

The following examples show how to use rx.functions.Actions. 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: HostCollector.java    From ocelli with Apache License 2.0 6 votes vote down vote up
protected void bindToInstanceLifecycle(Instance<ConnectionProvider<W, R>> i,
                                       final HostConnectionProvider<W, R> hcp,
                                       final Subscriber<? super List<HostConnectionProvider<W, R>>> o) {
    i.getLifecycle()
     .finallyDo(new Action0() {
         @Override
         public void call() {
             removeHost(hcp, o);
         }
     })
     .subscribe(Actions.empty(), new Action1<Throwable>() {
         @Override
         public void call(Throwable throwable) {
             // Do nothing as finallyDo takes care of both complete and error.
         }
     });
}
 
Example #2
Source File: TestActivity.java    From goro with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  GoroService.setup(this, Goro.create());

  Scheduler scheduler = new RxGoro(goro).scheduler("test-queue");
  Observable.just("ok")
      .subscribeOn(scheduler)
      .subscribe(new Action1<String>() {
        @Override
        public void call(String s) {
          result = "ok";
          resultSync.countDown();
        }
      });

  Observable.error(new RuntimeException("test error"))
      .subscribeOn(scheduler)
      .subscribe(Actions.empty(), new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) {
          error = throwable;
          errorSync.countDown();
        }
      });
}
 
Example #3
Source File: RXBusBuilder.java    From RXBus with Apache License 2.0 6 votes vote down vote up
public <R> Subscription subscribe(Action1<R> onNext, Action1<Throwable> onError,  Action0 onCompleted, Observable.Transformer<T, R> transformer)
{
    Observable observable = build(false);
    if (transformer != null)
        observable = observable.compose(transformer);

    if (onNext == null)
        onNext = Actions.empty();
    if (onError == null)
        onError = InternalObservableUtils.ERROR_NOT_IMPLEMENTED;
    if (onCompleted == null)
        onCompleted = Actions.empty();

    Action1<R> actualOnNext = onNext;
    if (mQueuer != null && mQueueSubscriptionSafetyCheckEnabled)
        actualOnNext = RXBusUtil.wrapQueueAction(onNext, mQueuer);

    observable = applySchedular(observable);
    Subscription subscription = observable.subscribe(actualOnNext, onError, onCompleted);
    if (mBoundObject != null)
        RXSubscriptionManager.addSubscription(mBoundObject, subscription);
    return subscription;
}
 
Example #4
Source File: DefaultCoreEnvironmentTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
private static void createAndShutdownDefaultEnvironment() {
    CoreEnvironment env = DefaultCoreEnvironment.create();
    env.scheduler().createWorker().schedule(Actions.empty());
    env.scheduler().createWorker().schedule(Actions.empty());
    env.scheduler().createWorker().schedule(Actions.empty());
    env.scheduler().createWorker().schedule(Actions.empty());
    env.scheduler().createWorker().schedule(Actions.empty());
    env.scheduler().createWorker().schedule(Actions.empty());
    boolean shutdownResult = env.shutdown();
    assertTrue(shutdownResult);
}
 
Example #5
Source File: UnicastAutoReleaseSubjectTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoTimeoutPostSubscription() throws Exception {
    TestScheduler testScheduler = Schedulers.test();
    UnicastAutoReleaseSubject<String> subject = UnicastAutoReleaseSubject.create(1, TimeUnit.DAYS, testScheduler);
    subject.onNext("Start the timeout now."); // Since the timeout is scheduled only after content arrival.
    final AtomicReference<Throwable> errorOnSubscribe = new AtomicReference<Throwable>();
    final CountDownLatch latch = new CountDownLatch(1);
    subject.subscribe(Actions.empty(), new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) {
            errorOnSubscribe.set(throwable);
            latch.countDown();
        }
    }, new Action0() {
        @Override
        public void call() {
            latch.countDown();
        }
    });

    testScheduler.advanceTimeBy(1, TimeUnit.DAYS);
    subject.onCompleted();

    latch.await(1, TimeUnit.MINUTES);

    Assert.assertNull("Subscription got an error.", errorOnSubscribe.get());
}
 
Example #6
Source File: Observable.java    From letv with Apache License 2.0 5 votes vote down vote up
public final Subscription subscribe(Action1<? super T> onNext, Action1<Throwable> onError) {
    if (onNext == null) {
        throw new IllegalArgumentException("onNext can not be null");
    } else if (onError != null) {
        return subscribe(new ActionSubscriber(onNext, onError, Actions.empty()));
    } else {
        throw new IllegalArgumentException("onError can not be null");
    }
}
 
Example #7
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<T> doOnTerminate(Action0 onTerminate) {
    return lift(new OperatorDoOnEach(new ActionSubscriber(Actions.empty(), Actions.toAction1(onTerminate), onTerminate)));
}
 
Example #8
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Subscription subscribe(Action1<? super T> onNext) {
    if (onNext != null) {
        return subscribe(new ActionSubscriber(onNext, InternalObservableUtils.ERROR_NOT_IMPLEMENTED, Actions.empty()));
    }
    throw new IllegalArgumentException("onNext can not be null");
}
 
Example #9
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Subscription subscribe() {
    return subscribe(new ActionSubscriber(Actions.empty(), InternalObservableUtils.ERROR_NOT_IMPLEMENTED, Actions.empty()));
}
 
Example #10
Source File: Completable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Completable doOnCompleted(Action0 onCompleted) {
    return doOnLifecycle(Actions.empty(), Actions.empty(), onCompleted, Actions.empty(), Actions.empty());
}
 
Example #11
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<T> doOnNext(Action1<? super T> onNext) {
    return lift(new OperatorDoOnEach(new ActionSubscriber(onNext, Actions.empty(), Actions.empty())));
}
 
Example #12
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<T> doOnError(Action1<Throwable> onError) {
    return lift(new OperatorDoOnEach(new ActionSubscriber(Actions.empty(), onError, Actions.empty())));
}
 
Example #13
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<T> doOnCompleted(Action0 onCompleted) {
    return lift(new OperatorDoOnEach(new ActionSubscriber(Actions.empty(), Actions.empty(), onCompleted)));
}
 
Example #14
Source File: Completable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Completable doAfterTerminate(Action0 onAfterComplete) {
    return doOnLifecycle(Actions.empty(), Actions.empty(), Actions.empty(), onAfterComplete, Actions.empty());
}
 
Example #15
Source File: Completable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Completable doOnSubscribe(Action1<? super Subscription> onSubscribe) {
    return doOnLifecycle(onSubscribe, Actions.empty(), Actions.empty(), Actions.empty(), Actions.empty());
}
 
Example #16
Source File: Completable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Completable doOnError(Action1<? super Throwable> onError) {
    return doOnLifecycle(Actions.empty(), onError, Actions.empty(), Actions.empty(), Actions.empty());
}
 
Example #17
Source File: Completable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Completable doOnUnsubscribe(Action0 onUnsubscribe) {
    return doOnLifecycle(Actions.empty(), Actions.empty(), Actions.empty(), Actions.empty(), onUnsubscribe);
}