reactive-programming

RxJS: How to have one Observer process multiple Observables?

回眸只為那壹抹淺笑 提交于 2019-12-22 06:30:01
问题 I am working with a framework that calls a function I implement. I would like the parameter of this function to be converted to an Observable, and sent through a sequence of Observers. I thought I could use a Subject for this, but it isn't behaving as I expected. To clarify, I have something like the following code. I thought Option 1 below would work, but so far I am settling for Option 2 , which doesn't seem idiomatic at all. var eventSubject = new Rx.Subject(); var resultSource =

Generate infinite sequence of Natural numbers using RxJava

做~自己de王妃 提交于 2019-12-22 05:29:14
问题 I am trying to write a simple program using RxJava to generate an infinite sequence of natural numbers. So, far I have found two ways to generate sequence of numbers using Observable.timer() and Observable.interval() . I am not sure if these functions are the right way to approach this problem. I was expecting a simple function like one we have in Java 8 to generate infinite natural numbers. IntStream.iterate(1, value -> value +1).forEach(System.out::println); I tried using IntStream with

reactive-banana throttling events

牧云@^-^@ 提交于 2019-12-22 04:48:15
问题 I would like to implement a certain type of throttling of events in reactive-banana. It should work such that an event is not let through if arrives at less then delta seconds from the last event that passed through. If it is not let through then it is stored and is fired after delta seconds from the last fired event. Below is a program that implements this for lists of time stamped numbers. Would it be possible to translate this to reactive-banana ? Also, in reactive-banana how do I fire an

Should rxjs subjects be public in the class?

吃可爱长大的小学妹 提交于 2019-12-22 04:42:29
问题 Let's say I have two classes, where you can observe over some observables. First example, with public subject: class EventsPub { public readonly onEnd = new Subject<void>(); } Second example, with private subject and registering method: class EventsPriv { private readonly endEvent = new Subject<void>(); public onEnd(cb: () => void): Subscription { return this.endEvent.subscribe(cb); } } The first example is somehow unsafe because anyone can call eventsPub.endEvent.next() from outside the

Filter list of objects in RxJava

孤者浪人 提交于 2019-12-22 03:50:27
问题 I am trying to filter the list on the basis of it's property. For example, Sensors class has a property isActive and I want to get all the objects with isActive as true but I am unable to do it. I tried different ways but I didn't find the solution. Can someone help me to do it? Here is my code: mCompositeDisposable.add( fcService.getStationList() .subscribeOn(Schedulers.io()) .flatMap( stations -> { return fcService.getSensorList(stations.get(0).getName().getOriginal()); }) .subscribe(this:

Spring WebFlux, unit testing Mono and Flux

非 Y 不嫁゛ 提交于 2019-12-21 19:25:41
问题 Interested in reactive programming, I played a bit with the Building a Reactive RESTful Web Service guide. And wanted to move forwrad and add some unit tests. I tried to test my handler ( RouterFunction ) with plain Junit/Mockito test. But, because it is reactive, the handler returns a Mono<ServerResponse> . So I had to block() it to test the ServerResponse status but was not able to extract his body to test it. While searching the web for a solution, it seems that all the samples are using

Get string value from Observable<string> in typescript and Angular

余生长醉 提交于 2019-12-21 18:00:09
问题 I want to get string value from Observable and return the value from the function to the caller function. For eg: I have array of keys and would like to fetch the value (string) of all key one by one and display it html component which has menu bar. Here are the ts files: key-list.component.ts public data = [ { 'key': 1, 'value' : this.getValue(1)}, { 'key': 2, 'value' : this.getValue(2)}, ... ]; private getValue(key: number): string { return this.keyService.find(key).subscribe(response => {

Rx how to group by a key a complex object and later do SelectMany without “stopping” the stream?

断了今生、忘了曾经 提交于 2019-12-21 17:45:01
问题 This is related to my other question here. James World presented a solution as follows: // idStream is an IObservable<int> of the input stream of IDs // alarmInterval is a Func<int, TimeSpan> that gets the interval given the ID var idAlarmStream = idStream .GroupByUntil(key => key, grp => grp.Throttle(alarmInterval(grp.Key))) .SelectMany(grp => grp.IgnoreElements().Concat(Observable.Return(grp.Key))); <edit 2: Question: How do I start the timers immediately without waiting for the first

Reactive Banana: how to use values from a remote API and merge them in the event stream

心不动则不痛 提交于 2019-12-21 17:22:33
问题 I am using Reactive-Banana in a WX interface. I need to retrieve a value from an external service API when a button is pressed. I have a generic Behavior based on the data type AppState that “accums” the transformed changes based on a function transformation ( doSomeTransformation ). The values that get transformed are transported by the events and they come from a remote API ( getRemoteValue ) when a button on the interface is pressed. I have written a slim version of the code that

is there an equivalent of async pipe that you can use inside a component?

孤人 提交于 2019-12-21 08:07:08
问题 Does there exist something equivalent to the async pipe that I could use inside a component like this @Component({ selector: 'my-component', }) export class myComponent { myObservable$: Observable<string>; method() { doSomething(this.myObservable$); // here I would like to access directly the current string value of // myObservable$ without having to subscribe } } 回答1: You have to ask yourself: What do you want to achieve by avoiding the subscribe() call? My guess is that you want to prevent