rxjs5

Angular 2 Http RetryWhen

此生再无相见时 提交于 2019-12-07 10:58:31
问题 I'm trying to use retryWhen in HTTP calls. It works perfectly when try to use like this: return this.http.get(`${environment.apiUrl}/track/${this.user.instance._id}/${this.currentPlayer.playlist.id}/next?s=${this.playerCounter}`, options) .timeout(500, new TimeoutError(`Timeout trying to get next track. [instanceId=${this.user.instance._id}]`)) .retryWhen(attempts => { return Observable.range(1, 3).zip(attempts, i => i).flatMap(i => 3 === i ? Observable.throw(attempts) : Observable.timer(i *

How to Return From Observable in TypeScript Method with Return Type

眉间皱痕 提交于 2019-12-07 10:31:42
问题 I have a Google geocode service in TypeScript. I need this method to return a "GoogleMap" class, after it fetches the lat/long for a given address. I created a TypeScript method that returns a "GoogleMap" type. But, I'm getting a function that is neither void nor any must return a value... Here's my method: getLatLongFromAddress(streetAddress: string): GoogleMap { this.geoCodeURL = GOOGLE_GEOCODE_BASE_URL + streetAddress + "&key=" + GOOGLE_MAPS_API_KEY; this.googleMap = new GoogleMap(); this

rxjs5 merge and error handling

你离开我真会死。 提交于 2019-12-07 06:15:30
问题 I would like to combine/merge multiple Observables and when each of them is completed execute a finally function. The merge operator seems to execute each subscription in parallel, which is what I need, but if any of them throws an error the execution is halted. RxJS version 4 has an operator mergeDelayError that should keep the all subscriptions executing till all of them are completed, but this operator isn't implemented in version 5 . Should I revert to a different operator? var source1 =

Batching using RxJS?

一世执手 提交于 2019-12-07 04:10:04
问题 I'm guessing this should be somewhat easy to achieve but I've having trouble (conceptually, I guess) figuring out how to tackle it. What I have is an API that returns an array of JSON objects. I need to step through these objects, and, for each object, make another AJAX call. The issue is the system that handles each AJAX call can only handle two active calls at a time (as it's quite a CPU-intensive task that hooks out into a desktop application). I was wondering how I could achieve this

Waiting for an observable to finish

…衆ロ難τιáo~ 提交于 2019-12-07 02:48:46
问题 I have a method that needs to wait for an observable to finish. I know observable are great for returning single pieces of data over time but I need to know when this observable has completely finished returning all of its data so I can run validation code on the object it has returned. The method getCustom subscribes to an observable run on the supplied url which then returns the observable. I am not too sure if this is the best way to approach this situation so I would appreciate if anyone

RxJs and Typescript. TS2307: Cannot find module '@reactivex/rxjs'

两盒软妹~` 提交于 2019-12-06 22:37:08
问题 I got a problem with typescript and RxJs v5. Please Look the UPDATE sections. I did yarn add @reactivex/rxjs (also yarn add rxjs ) and on my index.ts did import Rx from '@reactivex/rxjs'; and got this error: Also, if I run node ./node_modules/.bin/tsc I got this error back too error TS2307: Cannot find module '@reactivex/rxjs'. UPDATE Also doing import { Observable } from 'rxjs/Observable' throws the same error . UPDATE 2 Well this seems to be more related to TS itself than to RxJS.

“Unsubscribe” function callback/hook in Observable “executor” function

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 21:24:02
问题 I am confused about what the purpose of the "dispose" or "unsubscribe" function is for, which is (optionally) returned from an observable "executor" function, like so: const Rx = require('rxjs'); const obs = Rx.Observable.create(obs => { // we are in the Observable "executor" function obs.next(4); // we return this function, which gets called if we unsubscribe return function () { console.log('disposed'); } }); const s1 = obs.subscribe( function (v) { console.log(v); }, function (e) { console

Angular 2 / RXJS - need some help batching requests

本小妞迷上赌 提交于 2019-12-06 11:12:53
I keep reading rxjs documentation but getting lost in all the operators.. this is what i got so far let obs = Observable.from([1, 3, 5]) so what i need this to do is take() some set amount from the array. use the results in a post request, when that comes out successful then i need to restart the process. I want to collect all the results, and keep progress as the process is going (for a progress bar) I don't need the code for all of that. what i really need to know is how to use rxjs to split this array up.. send part of it, and restart the process until theres nothing left to send. FINAL

Implementing fromSubscriber in rxjs

♀尐吖头ヾ 提交于 2019-12-06 08:43:06
问题 I ran into an interesting issue today. I'm working on an app where we have file uploads, and we want to implement a progress bar. The app is written using React/Redux/Redux-Observable. I want to dispatch actions for upload progress. Here's what I did to implement it: withProgress(method, url, body = {}, headers = {}) { const progressSubscriber = Subscriber.create(); return { Subscriber: progressSubscriber, Request: this.ajax({ url, method, body, headers, progressSubscriber }), }; } I have a

How to use retryWhen with a function that returns a Boolean?

三世轮回 提交于 2019-12-06 08:19:01
Here's my code: this._http.post(this._url_get + extension, '', { headers: headers }) .map(res => res['_body']) .retryWhen(errors => {return responseErrorProcess(errors)}) now I need to catch exceptions and pass them to my responseErrorProcess() which returns true if it needs to retry I could not figure out how to retrieve the exceptions from errors , this is how it looks: Subject_isScalar: falseclosed: falsehasError: falseisStopped: falseobservers: Array[0]thrownError: null__proto__: Observable` It doesn't seem to contain errors about the exceptions that occurs, plus I couldn't figure out what