reactive-programming

Chaining Observables in RxJS

雨燕双飞 提交于 2019-12-17 04:28:19
问题 I'm learning RxJS and Angular 2. Let's say I have a promise chain with multiple async function calls which depend on the previous one's result which looks like: var promiseChain = new Promise((resolve, reject) => { setTimeout(() => { resolve(1); }, 1000); }).then((result) => { console.log(result); return new Promise((resolve, reject) => { setTimeout(() => { resolve(result + 2); }, 1000); }); }).then((result) => { console.log(result); return new Promise((resolve, reject) => { setTimeout(() =>

Reactor way to cancel Subscriptions

蹲街弑〆低调 提交于 2019-12-14 03:43:47
问题 I try to figure out Reactor Project and I'm looking for a way to cancel Subscriptions. I know that after making Subscription of for example Flux I can get reference to Cancellation object which can be used to send onCancel Signal, but this is only after making subscription and I need to hold that reference in some kind of Collection. Is there better way to get Cancellation object? Or just to cancel Subscriptions. Maybe some kind of place which contains reference to all active Subscriptions -

How to combine GroupedObservables in rx.net?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 20:14:09
问题 I have one observable that I use GroupBy on to get a number of streams. I actually want a Scan result over each sub-stream. Let's say the observable is over product prices and the scan result is average price per product type. I have another stream of events pertaining to those 'products' (let's say "show product price" events) and I want to combine it with the previous stream's latest product price. So the Scan output per group needs to be combined with each element of the event stream to

Merging Observables with feedback, merging Observable with Itself

可紊 提交于 2019-12-13 17:56:16
问题 I need to create Observable, that will collect information from different sources(other Observables), and each source has impact on the event value, but still, the value is built based on previous value(kind of state machine). We have message with int value and operation code: class Message{ Integer value; String operation; public Message(Integer value, String operation) { this.value = value; this.operation = operation; } } And some source of such values, with init value: Observable<Message>

Import of lettable operators and observable creation methods

徘徊边缘 提交于 2019-12-13 15:23:11
问题 I'm upgrading to Angular 5 and RxJS 5.5.2 and trying to import Observable.of operator. Before lettable operators, we did it like this: import 'rxjs/add/observable/of'; // Usage Observable.of(...) But now importing from paths containing add is discouraged. So what is the proper way of importing and using lettable static operators now? 回答1: The operators that have now a lettable version are the instance operators. Since before 5.5.x of and any other observable creation methods can be used as in

How to delay event emission with rxpy/rxjs?

不羁岁月 提交于 2019-12-13 14:59:39
问题 I've got two event streams. One is from an inductance loop, the other is an IP camera. Cars will drive over the loop and then hit the camera. I want to combine them if the events are within N milliseconds of each other (car will always hit the loop first), but I also want the unmatched events from each stream (either hardware can fail) all merged into a single stream. Something like this: ---> (only unmatched a's, None) / \ stream_a (loop) \ \ \ --> (a, b) ---------------------------> (Maybe

RxJava/Android: Combine result of two dependent Observables

独自空忆成欢 提交于 2019-12-13 12:25:46
问题 I have two Observables . Observable<A> getAObservable() Returns Observable of A Observable<B> getBObservable(A) Returns Observable of 'B'. Here Observable<A> should execute before Observable<B> so that it can pass its result A to getBObservable() method. Now once Observable<B> completes I need to combine the result of these observable and Observable<AB> should returns. Options Tried: Take Observable<A> and apply flatMap on it so that it transform result in B . Now at this point I am not

Subscribing to a future observable

十年热恋 提交于 2019-12-13 09:13:25
问题 I have na event-based API (Geolocator) that I want to convert to Rx . The problem is that some operations require that all events are unsubscribed and I don't want to pass that burdon to the user of the Rx API. So, the user will subscribe to a few observables and when the events are subscribed they are published to those observables. What's the best way to do this? I thought of creating a subject that the users subscribe to and then have the events published to those through another set of

Any Rx operator that returns both the input variable and the result?

我们两清 提交于 2019-12-13 07:35:44
问题 When using Rx (specifically, RxJava), is there an operator that will package the input variable along with the function's output, in order to use both in the next step? For example, let's say I start with a list of Tweet ID's, and my program a) does a REST call to get the text of that tweet and b) saves the id and text into a local database. A normal "map" will return the text for step a, but it discards the original id. In code: Observable.from(tweet_id_list) .specialMap(i -> getTweetText(i)

Multiple RxJS AJAX Requests

血红的双手。 提交于 2019-12-13 06:34:11
问题 I'm using rxjs to make several http requests and I want to end up with an object that looks something like: { 100: { ...response from api call... }, 205: { ...response from api call... }, ...etc... } Here's what I have so far: const projectIds = [100, 205, 208, 300] const source = Rx.Observable .from(projectIds) .flatMap(id => get(`projects/${id}/builds`)) .map(response => response['data']) .zip(projectIds) .toArray() source.subscribe(pipelines => { console.log(pipelines) }) This gives me