本文整理汇总了Java中io.reactivex.Flowable.fromCallable方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.fromCallable方法的具体用法?Java Flowable.fromCallable怎么用?Java Flowable.fromCallable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.fromCallable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callReact
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* This method prepares and executes a reactive based REST communication
*
* @param httpRequest,
* a prepared {@link HttpRequest} used for api call
* @param consumerOnSuccess,
* the provided consumer that react to http response
* @param consumerOnError,
* the provided consumer that react to http error
* @param attempts,
* the number of attempts to test if an error occurs during the api
* call
*/
public static void callReact(HttpRequest httpRequest,
io.reactivex.functions.Consumer<HttpResponse> consumerOnSuccess,
io.reactivex.functions.Consumer<Throwable> consumerOnError, int attempts) {
if (consumerOnSuccess == null) {
LOGGER.error("Reactive consumer on success cannot be null");
return;
}
// prepare flowable to handle async response
Flowable<HttpResponse> flowable = Flowable.fromCallable(() -> RestService.callSync(httpRequest, attempts));
new Thread(() -> {
if (consumerOnError == null) {
LOGGER.debug("No consumer on error specified, using a default one");
flowable.subscribe(consumerOnSuccess, err -> {
// unhandled event
LOGGER.error("Default consumer onError has received: " + err.getMessage());
});
} else {
flowable.subscribe(consumerOnSuccess, consumerOnError);
}
flowable.publish();
}).start();
}
示例2: getResponse
import io.reactivex.Flowable; //导入方法依赖的package包/类
private Flowable<Response> getResponse(final HttpUrl url) {
return Flowable.fromCallable(new Callable<Response>() {
@Override
public Response call() throws Exception {
System.out.println(url);
Request request = ServiceInjector.resolve(ServiceConfiguration.class).getRequestBuilder()
.url(url)
.build();
return ServiceInjector.resolve(OkHttpClient.class).newCall(request).execute();
}
});
}
示例3: getResponseFromPost
import io.reactivex.Flowable; //导入方法依赖的package包/类
private Flowable<Response> getResponseFromPost(final HttpUrl url, final String body) {
return Flowable.fromCallable(new Callable<Response>() {
@Override
public Response call() throws Exception {
System.out.println(url);
Request request = ServiceInjector.resolve(ServiceConfiguration.class).getRequestBuilder()
.post(RequestBody.create(MediaType.parse("application/json"), body))
.url(url)
.build();
return ServiceInjector.resolve(OkHttpClient.class).newCall(request).execute();
}
});
}
示例4: apply
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Override
public Flowable<String> apply(final Response response) {
return Flowable.fromCallable(new Callable<String>() {
@Override
public String call() throws Exception {
if (!response.isSuccessful()) {
throw new IOException(response.message());
}
String responseString = response.body().string();
System.out.println(responseString);
return responseString;
}
});
}
示例5: processAsync
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* This method leverages the {@link #process(List)} method to asynchronously)}
* handle the dataset
*
* @param datasource dataset that should be processed
*/
default Flowable<List<List<Transmutation>>> processAsync(List<T> datasource) {
return Flowable.fromCallable(() -> process(datasource));
}
示例6: processAsync
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* This method leverages the {@link #process(List, List)} method to asynchronously)}
* load data to the dataset
*
* @param data dataset that should be processed
* @param destinations where the data should be loaded to
*/
default Flowable<List<Boolean>> processAsync(List<Transmutation> data, List<T> destinations) {
return Flowable.fromCallable(() -> process(data, destinations));
}