io.reactivex.rxjava3.functions.Supplier Java Examples

The following examples show how to use io.reactivex.rxjava3.functions.Supplier. 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: Transformers.java    From mobius with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an {@link ObservableTransformer} that will flatten the provided {@link Function} into
 * the stream as an {@link Observable} every time it receives an effect from the upstream effects
 * observable. This will result in calling the function on the specified scheduler, and passing it
 * the requested effect object then emitting its returned value.
 *
 * @param function the {@link Function} to be invoked every time the effect is requested
 * @param scheduler the {@link Scheduler} to be used when invoking the function
 * @param <F> the type of Effect this transformer handles
 * @param <E> the type of Event this transformer emits
 * @return an {@link ObservableTransformer} that can be used with a {@link
 *     RxMobius.SubtypeEffectHandlerBuilder}.
 */
static <F, E> ObservableTransformer<F, E> fromFunction(
    final Function<F, E> function, @Nullable final Scheduler scheduler) {
  return new ObservableTransformer<F, E>() {
    @Override
    public ObservableSource<E> apply(Observable<F> effectStream) {
      return effectStream.flatMap(
          new Function<F, ObservableSource<E>>() {
            @Override
            public ObservableSource<E> apply(@NonNull F f) {
              Observable<E> eventObservable =
                  Observable.fromSupplier(
                      new Supplier<E>() {
                        @Override
                        public E get() throws Throwable {
                          return function.apply(f);
                        }
                      });
              return scheduler == null ? eventObservable : eventObservable.subscribeOn(scheduler);
            }
          });
    }
  };
}
 
Example #2
Source File: Rx3Idler.java    From RxIdler with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a function which wraps the supplied {@link Scheduler} in one which notifies Espresso as
 * to whether it is currently executing work or not.
 * <p>
 * Note: Work scheduled in the future does not mark the idling resource as busy.
 */
@SuppressWarnings("ConstantConditions") // Public API guarding.
@CheckResult @NonNull
public static Function<Supplier<Scheduler>, Scheduler> create(@NonNull final String name) {
  if (name == null) throw new NullPointerException("name == null");
  return delegate -> {
    IdlingResourceScheduler scheduler =
        new DelegatingIdlingResourceScheduler(delegate.get(), name);
    IdlingRegistry.getInstance().register(scheduler);
    return scheduler;
  };
}
 
Example #3
Source File: RequestContextSupplierFlowable.java    From armeria with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T get() throws Throwable {
    try (SafeCloseable ignored = assemblyContext.push()) {
        return ((Supplier<T>) source).get();
    }
}
 
Example #4
Source File: RequestContextSupplierSingle.java    From armeria with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T get() throws Throwable {
    try (SafeCloseable ignored = assemblyContext.push()) {
        return ((Supplier<T>) source).get();
    }
}
 
Example #5
Source File: RequestContextSupplierMaybe.java    From armeria with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T get() throws Throwable {
    try (SafeCloseable ignored = assemblyContext.push()) {
        return ((Supplier<T>) source).get();
    }
}
 
Example #6
Source File: RequestContextSupplierObservable.java    From armeria with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T get() throws Throwable {
    try (SafeCloseable ignored = assemblyContext.push()) {
        return ((Supplier<T>) source).get();
    }
}