reactive-programming

RxJava retryWhen bizarre behavior

。_饼干妹妹 提交于 2019-12-09 13:01:41
问题 I'm playing with the RxJava retryWhen operator. Very little is found about it on the internet, the only one worthy of any mention being this. That too falls short of exploring the various use cases that I'd like to understand. I also threw in asynchronous execution and retry with back-off to make it more realistic. My setup is simple: I've a class ChuckNorrisJokesRepository that returns random number of Chuck Norris jokes from a JSON file. My class under test is ChuckNorrisJokesService which

How to mock Spring WebFlux WebClient?

偶尔善良 提交于 2019-12-09 07:48:19
问题 We wrote a small Spring Boot REST application, which performs a REST request on another REST endpoint. @RequestMapping("/api/v1") @SpringBootApplication @RestController @Slf4j public class Application { @Autowired private WebClient webClient; @RequestMapping(value = "/zyx", method = POST) @ResponseBody XyzApiResponse zyx(@RequestBody XyzApiRequest request, @RequestHeader HttpHeaders headers) { webClient.post() .uri("/api/v1/someapi") .accept(MediaType.APPLICATION_JSON) .contentType(MediaType

How to properly handle onError inside RxJava (Android)?

时光毁灭记忆、已成空白 提交于 2019-12-09 07:38:07
问题 I'm getting a list of installed apps on the device. It's a costly operation, so I'm using Rx for that: Observable<List> observable = Observable.create(subscriber -> { List result = getUserApps(); subscriber.onNext(result); subscriber.onError(new Throwable()); subscriber.onCompleted(); }); observable .map(s -> { ArrayList<String> list = new ArrayList<>(); ArrayList<Application> applist = new ArrayList<>(); for (Application p : (ArrayList<Application>) s) { list.add(p.getAppName()); applist.add

Why Spring ReactiveMongoRepository does't have save method for Mono?

北慕城南 提交于 2019-12-09 03:22:32
问题 I have a MovieRepository which extended ReactiveMongoRepository. I want to save a single POJO in a reactive way. But ReactiveMongoRepository doesn't provide save method for Mono or Publisher. I have to use block() method or use the saveAll method in the ReactiveMongoRepository. public Mono<ServerResponse> create(ServerRequest request) { Mono<Movie> movieMono = request.bodyToMono(Movie.class); return movieRepository.save(movieMono.block()) // .flatMap((movie) -> ServerResponse.ok().body

How to handle onError inside RxJava. I am getting “OnErrorNotImplementedException”

时光毁灭记忆、已成空白 提交于 2019-12-08 21:36:36
问题 In my app I am using ReactiveLocationProvider library (link). I subscribe for updates in the onCreate method. It works fine when the device is online but if I switch my wifi off and wait for the next background location updates the device OnErrorNotImplementedException. This is the log: 12-30 00:05:44.711 12237-12237/koemdzhiev.com.stormy E/AndroidRuntime: FATAL EXCEPTION: main Process: koemdzhiev.com.stormy, PID: 12237 java.lang.IllegalStateException: Exception thrown on Scheduler.Worker

RxJS reduce doesn't continue

三世轮回 提交于 2019-12-08 20:23:14
问题 Why doesn't the flatMap cause downstream reductions to fire? I got code like: handleFiles.flatMap(files => Rx.Observable.from(files). flatMap((file, i) => fileReader(file, i)). reduce((form, file, i) => { form.append('file[' + i + ']', result); console.log('reduce step', file); return form; }, new FormData()). tap(console.log.bind(console, 'after reduce')) ). subscribe(console.log.bind(console, 'response')); And the problem is that the 'after reduce' tap is never hit. Why? The log is like:

RxJava Observable and Subscriber for skipping exception?

↘锁芯ラ 提交于 2019-12-08 16:00:58
问题 If I have an Observalbe : List<Integer> ints = Lists.newArrayList(1, 2, 0, 3, 4); Observable<Integer> o1 = Observable.from(ints); I want to generate another observable , which divide by 12 : Observable<Integer> o2 = o1.map(i -> 12/i); o2.subscribe( v -> logger.info ("Subscriber value {}", v) , t -> logger.error("Subscriber onError {} : {}", t.getClass() , t.getMessage()) ); It's obvious it will got error , and stopped when it encounter '0' : RxTest - Subscriber value 12 RxTest - Subscriber

How to handle network failure in React-Native, when network is off

亡梦爱人 提交于 2019-12-08 15:20:58
问题 How to handle network failure in React-Native, when device not connected to network. My scenario is am trying to connect some api, while fetching request if network is disconnected react-native throws network request failed error. how to handle this scenario to give the user best user experience. How to handle Network request failed in a better way. 回答1: Use NetInfo like this: // Check for network connectivity NetInfo.isConnected.fetch().done((isConnected) => { if ( isConnected ) { // Run

FlatList onEndReached being called multiple times

余生颓废 提交于 2019-12-08 15:19:15
问题 I'm making a react native project where user can search images using Flickr API, Everything else is working fine but the problem i'm having while implementing pagination. I have used FlatList's onEndReached to detect when user has scrolled to the end on the list, but the problem is onEndReached is being called multiple times(including one during the first render). I have even disabled bounce as said here but it's still being called more than once export default class BrowserHome extends React

Simple Example for Scala React

陌路散爱 提交于 2019-12-08 10:49:03
问题 Based on the paper Deprecating the Observer Pattern with Scala.React I tried to set up a simple example from the paper, but it throwed an exception Exception in thread "main" java.lang.AssertionError: assertion failed: This method must be run on its domain scala.react.NilDebug@1502c065 A related question is Running a simple Scala.React expression. How do I set up everything to use the great power of the scala react library? Besides the library scala-react, I used the following example: object