reactive-programming

What's the point of .switchIfEmpty() getting evaluated eagerly?

半世苍凉 提交于 2019-12-23 02:09:12
问题 Even if my stream is not empty, the fallback stream would always be created? What's the intent behind doing this? This is extremely non-idiomatic. On the other hand, . onErrorResume is evaluated lazily. Could someone please explain to me why . switchIsEmpty is evaluated eagerly? Here's the code: public static void main(String[] args) { Mono<Integer> m = Mono.just(1); m.flatMap(a -> Mono.delay(Duration.ofMillis(5000)).flatMap(p -> Mono.empty())) .switchIfEmpty(getFallback()) .doOnNext(a ->

how to move one component to another component on button click in react?

情到浓时终转凉″ 提交于 2019-12-23 01:54:05
问题 could you please tell me how to move one component to another component on button click in react ? I get the react-router.js from cdn .I don't know how to use this js ..I want to show second component on button click of first component` here is my code http://codepen.io/anon/pen/jVoZjW?editors=1010 class Abc extends React.Component { handle(){ alert('move to second component') } render (){ return (<div><h1>second</h1><button onClick={this.handle}>move to second page</button></div>); } } class

Recognizing and exact series of events in RxJS

风格不统一 提交于 2019-12-23 01:45:41
问题 Using RxJS, I want to fire an event if the user types 'a' then 'b' then 'c'. I do not want the event fired if they enter 'a' then 'b' then 'z' then 'c'. Here is my codepen of the work I have done so far (in TypeScript). class App1 { private divStream: HTMLElement; private divResult: HTMLElement; constructor(divStream: HTMLElement, divResult: HTMLElement) { this.divStream = divStream; this.divResult = divResult; } start() { var filterByCharacter = (expectedCharater) => { return (char) => {

How to batch long process in serial using RxJava?

我是研究僧i 提交于 2019-12-22 18:48:12
问题 I have a big list of strings that needs to be checked against remote API. Observable.from(List<String> strings) // let's say the `strings` has > 5000 items .buffer(50) // splitting the strings into 50-sized chunks, it returns Observable<List<String>> (fast) .flatMap((strings) -> { // checkPhoneNumbers is a network call using Retrofit's RxJava (slow) return mSyncApi.checkPhoneNumbers(strings); }) .reduce( ... ) // aggregate all checking results .subscribe( ... ); The problem is buffer() seems

Should I rely on “mono of item” or “plain item” arguments when composing reactive chains?

自作多情 提交于 2019-12-22 17:24:21
问题 I am have two versions of a Webflux/Reactor handler class. This class mimics a user sign up use case - as far as the business logic is concerned. The first version of the class relies upon a Mono<User> whereas the second version uses a plain User . First version of the class : this is the version relying on a Mono<User> argument down the chain. Notice the top level public method createUser uses a userMono . @Component @RequiredArgsConstructor public class UserHandler { private final @NonNull

Should I rely on “mono of item” or “plain item” arguments when composing reactive chains?

ぐ巨炮叔叔 提交于 2019-12-22 17:22:56
问题 I am have two versions of a Webflux/Reactor handler class. This class mimics a user sign up use case - as far as the business logic is concerned. The first version of the class relies upon a Mono<User> whereas the second version uses a plain User . First version of the class : this is the version relying on a Mono<User> argument down the chain. Notice the top level public method createUser uses a userMono . @Component @RequiredArgsConstructor public class UserHandler { private final @NonNull

Reset timeout on event with RxJS

ぐ巨炮叔叔 提交于 2019-12-22 14:58:23
问题 I'm experimenting with RxJS (with the JQuery extension) and I'm trying to solve the following use case: Given that I have two buttons (A & B) I'd like to print a message if a certain "secret combination" is clicked within a given timeframe. For example the "secret combination" could be to click "ABBABA" within 5 seconds. If the combination is not entered within 5 seconds a timeout message should be displayed. This is what I currently have: var secretCombination = "ABBABA"; var buttonA = $("

waiting IObservable to get all elements error

只谈情不闲聊 提交于 2019-12-22 10:59:43
问题 I have this class: public class TestService { public IObservable<int> GetObservable(int max) { var subject = new Subject<int>(); Task.Factory.StartNew(() => { for (int i = 0; i < max; i++) { subject.OnNext(i); } subject.OnCompleted(); }); return subject; } } I wrote a test method for this as well: [TestMethod] public void TestServiceTest1() { var testService = new TestService(); var i = 0; var observable = testService.GetObservable(3); observable.Subscribe(_ => { i++; }); observable.Wait();

Functional reactive operator for custom filter based on another Observable

北慕城南 提交于 2019-12-22 10:28:58
问题 For fun and to learn I'm trying to implement an undo system in my app using functional reactive programming. I have a stream of state changes, which need to be saved onto the undo stack. When the user clicks undo, I take a value from the stack and update application state accordingly. The problem is that this update itself also generates an event in the state change stream. So what I would like is to derive another stream from state changes, which ommits state change right after undo. A

Conditional emission delays with rxjs

删除回忆录丶 提交于 2019-12-22 09:56:37
问题 From picture to code? How to get the Out observable from Data and Gates? Data is an observable of any kind e.g. JSON objects to be sent to a remote backend Gates is a boolean observable, where the ticks correspond to true and the crosses to false. For example, Internet connectivity whereby true means the network became accessible and false reflects a disconnection. Out is the resulting observable, which emits the same as Data, sometimes immediately, sometimes with a delay, depending on the