reactive-programming

Mapping exception in RxJava 2

前提是你 提交于 2019-12-02 06:08:00
问题 How can I map one occurred exception to another one in RxJava2? For example: doOnError(throwable -> { if (throwable instanceof FooException) { throw new BarException(); } }) In this case I finally receive CompositeException that consists of FooException and BarException , but I'd like to receive only BarException . Help! 回答1: You can use onErrorResumeNext and return Observable.error() from it: source.onErrorResumeNext(e -> Observable.error(new BarException())) Edit This test passes for me:

Issue with Project Reactor's or() operator usage

强颜欢笑 提交于 2019-12-02 04:55:22
I would like to chain Mono s and emit the first non-empty of them. I thought the or() operator was designed for this purpose. Here is my chain of Mono s: first one is empty and second one should emit "hello". @Test void orTest() { Mono<String> chain = Mono.<String>empty().or(Mono.just("hello")); StepVerifier.create( chain ) .expectNext("hello") .verifyComplete(); } However, I get the following failure: java.lang.AssertionError: expectation "expectNext(hello)" failed (expected: onNext(hello); actual: onComplete()) Can someone please help? What I am getting wrong here? You misunderstand or() -

How to implement observeLatestOn in RxJava (RxScala)?

匆匆过客 提交于 2019-12-02 04:27:17
问题 I'm trying to implement the ObserveLatestOn operator in RxJava (actually, RxScala). This operator is useful, when we've got a fast producer and a slow subscriber, but the subscriber doesn't care about any items lost while it was consuming an item. A marble diagram: --1---2---3----------5------6--7-8-9------| --1=========>3===>---5=======>6======>9==>| The = character represents a long-running work being performed by the subscriber, the > character represents the work just finishing. As the

Rxjs - Consume API output and re-query when cache is empty

烂漫一生 提交于 2019-12-02 04:11:17
I'm trying to implement a version of this intro to RxJS ( fiddle here ) that instead of picking a random object from a returned API array, it consumes a backthrottled stream of objects from the returned API array. Here's a portion of the code that produces a controlled Observable from the API response (full fiddle here ): var responseStream = requestStream.flatMap(function (requestUrl) { return Rx.Observable.fromPromise(fetch(requestUrl)); }).flatMap(function(response) { return Rx.Observable.fromPromise(response.json()); }).flatMap(function(json) { return Rx.Observable.from(json); })

Cannot find module 'minizlib'

我与影子孤独终老i 提交于 2019-12-02 04:09:34
I am pretty new to React-Native. I install react-native on my Mac using the code below: npm install react-native -g react-native-cli I got the error: npm ERR! code MODULE_NOT_FOUND npm Err! Cannot find module 'minizlib' Anyone can help me to solve this problem please? New to this myself as a disclaimer but you may want to try uninstalling node. If you installed node with Homebrew try... $ brew uninstall node $ brew install node Try this brew install node brew install watchman npm install -g react-native-cli react-native init AwesomeProject Follow the exact steps in https://facebook.github.io

Is RxJava a good fit for branching workflows?

主宰稳场 提交于 2019-12-02 03:25:09
I am using RxJava to process some notifications that we pull from a queue. RxJava seemed to work fine with a simple workflow, now with new requirements coming in, the flow is growing in complexity with more branches (please see below picture as a reference) I tried to exemplify the flow with a small unit test: @Test public void test() { Observable.range(1, 100) .groupBy(n -> n % 3) .toMap(GroupedObservable::getKey) .flatMap(m1 -> { Observable<Integer> ones1 = m1.get(0); Observable<Integer> twos1 = m1.get(1).map(n -> n - 10); Observable<Integer> threes = m1.get(2).map(n -> n + 100); Observable

Mapping exception in RxJava 2

守給你的承諾、 提交于 2019-12-02 02:20:56
How can I map one occurred exception to another one in RxJava2? For example: doOnError(throwable -> { if (throwable instanceof FooException) { throw new BarException(); } }) In this case I finally receive CompositeException that consists of FooException and BarException , but I'd like to receive only BarException . Help! You can use onErrorResumeNext and return Observable.error() from it: source.onErrorResumeNext(e -> Observable.error(new BarException())) Edit This test passes for me: @Test public void test() { Observable.error(new IOException()) .onErrorResumeNext((Throwable e) -> Observable

Merging async iterables in python3

送分小仙女□ 提交于 2019-12-01 21:12:16
问题 Is there a good way, or a well-supported library, for merging async iterators in python3? The desired behavior is basically the same as that of merging observables in reactivex. That is, in the normal case, if I'm merging two async iterator, I want the resulting async iterator to yield results chronologically. An error in one of the iterators should derail the merged iterator. (Source: http://reactivex.io/documentation/operators/merge.html) This is my best attempt, but it seems like something

FormControl.detectchanges - why use distinctUntilChanged?

谁都会走 提交于 2019-12-01 18:01:07
Reading How to use RxJs distinctUntilChanged? and this , it seems that distinctUntilChanged alters the output stream to only provide distinct contiguous values . I take that to mean that if the same value arrives in immediate succession, you are essentially filtering the stream and only getting one occurrence of that repeated value. So if I write this: this.myFormControl.valueChanges .debounceTime(1000) .distinctUntilChanged() .subscribe(newValue => { console.log('debounced: ', newValue); }); I see no difference in output to this: this.myFormControl.valueChanges .debounceTime(1000) .subscribe

RxJS: Splitting an array result from Observable.fromPromise

廉价感情. 提交于 2019-12-01 15:41:00
I'm using RxJS here and I can't seem to get over this seemingly simple issue. rx.Observable .from([1,2,3,54,3,22,323,23,11,2]) .distinct() .subscribe(function next (x) { console.log('Next'); console.log(x); }, function error (x) { console.log('Error'); console.log(x); }, function completed () { console.log('Completed'); }); The above code spits out each array item in order as expected. rx.Observable .fromPromise(getNumbers([1,2,3,54,3,22,323,23,11,2])) .distinct() .subscribe(function next (x) { console.log('Next'); console.log(x); }, function error (x) { console.log('Error'); console.log(x); }