Java Code Examples for io.reactivex.functions.Action#run()

The following examples show how to use io.reactivex.functions.Action#run() . 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: OperatorsTest.java    From Java-programming-methodology-Rxjava-articles with Apache License 2.0 6 votes vote down vote up
public static <T> ObservableOperator<T,T> doOnEmpty(Action action){
    return observer -> new DisposableObserver<T>() {
        boolean isEmpty = true;
        @Override
        public void	onNext(T value) {
            isEmpty = false;
            observer.onNext(value);
        }
        @Override
        public void onError(Throwable t) {
            observer.onError(t);
        }
        @Override
        public void onComplete() {
            if (isEmpty) {
                try {
                    action.run();
                } catch (Exception e) {
                    onError(e);
                    return;
                }
            }
            observer.onComplete();
        }
    };
}
 
Example 2
Source File: BindingAdapters.java    From android-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingConversion
public static View.OnClickListener toOnClickListener(final Action listener) {
    if (listener != null) {
        return new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    listener.run();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
    } else {
        return null;
    }
}
 
Example 3
Source File: WriteStreamObserverImpl.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
private void writeStreamEnd(AsyncResult<Void> result) {
  try {
    Action a;
    if (result.succeeded()) {
      synchronized (this) {
        a = writeStreamEndHandler;
      }
      if (a != null) {
        a.run();
      }
    } else {
      Consumer<? super Throwable> c;
      synchronized (this) {
        c = this.writeStreamEndErrorHandler;
      }
      if (c != null) {
        c.accept(result.cause());
      }
    }
  } catch (Throwable t) {
    Exceptions.throwIfFatal(t);
    RxJavaPlugins.onError(t);
  }
}
 
Example 4
Source File: WriteStreamSubscriberImpl.java    From vertx-rx with Apache License 2.0 6 votes vote down vote up
private void writeStreamEnd(AsyncResult<Void> result) {
  try {
    Action a;
    if (result.succeeded()) {
      synchronized (this) {
        a = writeStreamEndHandler;
      }
      if (a != null) {
        a.run();
      }
    } else {
      Consumer<? super Throwable> c;
      synchronized (this) {
        c = this.writeStreamEndErrorHandler;
      }
      if (c != null) {
        c.accept(result.cause());
      }
    }
  } catch (Throwable t) {
    Exceptions.throwIfFatal(t);
    RxJavaPlugins.onError(t);
  }
}
 
Example 5
Source File: DatabaseExport.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings({"PMD.PrematureDeclaration", "PMD.PreserveStackTrace"})
private void wrapAction(Action action, String tag) {
    long startMillis = System.currentTimeMillis();
    try {
        action.run();
    } catch (Exception e) {
        throw new RuntimeException("Exception thrown during database export action: " + tag);
    }
    long endMillis = System.currentTimeMillis();

    Log.e("DatabaseExport", tag + ": " + (endMillis - startMillis) + "ms");
}