Java Code Examples for io.reactivex.rxjava3.core.Flowable#create()

The following examples show how to use io.reactivex.rxjava3.core.Flowable#create() . 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: DefaultDispatchManager.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Flowable<T> asFlowable(final BackpressureStrategy backpressureStrategy) {
    return Flowable.create(emitter -> {
        internalHandler = emitter::onNext;
        emitter.setCancellable(this::close);
    }, backpressureStrategy);
}
 
Example 2
Source File: RequestContextAssemblyTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
static Flowable<String> flowable(int count) {
    RequestContext.current();
    return Flowable.create(emitter -> {
        pool.submit(() -> {
            for (int i = 0; i < count; i++) {
                emitter.onNext(String.valueOf(count));
            }
            emitter.onComplete();
        });
    }, BackpressureStrategy.BUFFER);
}
 
Example 3
Source File: RxJava3FlowableService.java    From cxf with Apache License 2.0 5 votes vote down vote up
@GET
@Produces("application/json")
@Path("textJsonImplicitList")
public Flowable<HelloWorldBean> getJsonImplicitList() {
    return Flowable.create(subscriber -> {
        Thread t = new Thread(() -> {
            subscriber.onNext(new HelloWorldBean("Hello"));
            sleep();
            subscriber.onNext(new HelloWorldBean("Ciao"));
            sleep();
            subscriber.onComplete();
        });
        t.start();
    }, BackpressureStrategy.MISSING);
}
 
Example 4
Source File: FlowableRxInvokerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private <T> Flowable<T> create(Supplier<T> supplier) {
    Flowable<T> flowable = Flowable.create(new FlowableOnSubscribe<T>() {
        @Override
        public void subscribe(FlowableEmitter<T> emitter) throws Exception {
            try {
                T response = supplier.get();
                if (!emitter.isCancelled()) {
                    emitter.onNext(response);
                }
                
                if (!emitter.isCancelled()) {
                    emitter.onComplete();
                }
            } catch (Throwable e) {
                if (!emitter.isCancelled()) {
                    emitter.onError(e);
                }
            }
        }
    }, BackpressureStrategy.DROP);
    
    if (sc == null) {
        return flowable.subscribeOn(Schedulers.io());
    }
    
    return flowable.subscribeOn(sc).observeOn(sc);
}
 
Example 5
Source File: DataServiceImpl.java    From java-11-examples with Apache License 2.0 4 votes vote down vote up
@Override
public Flowable<DataItem> getDataFlowWithBackPressure(DataQuery dataQuery) {
    return Flowable.create(new FlowableDataProducer(executor, dataQuery), BackpressureStrategy.BUFFER);
}
 
Example 6
Source File: Rx3Apollo.java    From apollo-android with MIT License 4 votes vote down vote up
@NotNull
@CheckReturnValue
public static <T> Flowable<Response<T>> from(@NotNull final ApolloSubscriptionCall<T> call,
    @NotNull BackpressureStrategy backpressureStrategy) {
  checkNotNull(call, "originalCall == null");
  checkNotNull(backpressureStrategy, "backpressureStrategy == null");
  return Flowable.create(new FlowableOnSubscribe<Response<T>>() {
    @Override public void subscribe(final FlowableEmitter<Response<T>> emitter) throws Exception {
      cancelOnFlowableDisposed(emitter, call);
      call.execute(
          new ApolloSubscriptionCall.Callback<T>() {
            @Override public void onResponse(@NotNull Response<T> response) {
              if (!emitter.isCancelled()) {
                emitter.onNext(response);
              }
            }

            @Override public void onFailure(@NotNull ApolloException e) {
              Exceptions.throwIfFatal(e);
              if (!emitter.isCancelled()) {
                emitter.onError(e);
              }
            }

            @Override public void onCompleted() {
              if (!emitter.isCancelled()) {
                emitter.onComplete();
              }
            }

            @Override public void onTerminated() {
              onFailure(new ApolloSubscriptionTerminatedException("Subscription server unexpectedly terminated "
                  + "connection"));
            }

            @Override public void onConnected() {
            }
          }
      );
    }
  }, backpressureStrategy);
}
 
Example 7
Source File: RxQuery.java    From objectbox-java with Apache License 2.0 2 votes vote down vote up
/**
 * The returned Flowable emits Query results one by one. Once all results have been processed, onComplete is called.
 * Uses given BackpressureStrategy.
 */
public static <T> Flowable<T> flowableOneByOne(final Query<T> query, BackpressureStrategy strategy) {
    return Flowable.create(emitter -> createListItemEmitter(query, emitter), strategy);
}