observable

How can I reuse a Subscriber between two Observables (RxJava)

柔情痞子 提交于 2019-12-22 08:47:22
问题 In order to not repeat myself, I want to re-use a Subscriber variable between two observables. How do you do accomplish this? My current code below does not work, because after the subscriber is used once, it is unsubscribed and no longer works again. If I new a Subscriber instead of reusing a variable, my subscription works. I don't want to write the same code twice, if possible. public class HomePresenter extends BasePresenter<HomeView> { ArticleRepo articleRepo; @Inject public

Angular2 observable http get conditional repeat

爷,独闯天下 提交于 2019-12-22 08:22:41
问题 I'm using angular2 observable pattern to make http requests. I'm trying to conditional repeat the http get: I want to execute the http get until a condition is met: http.get('url') .map(res => { // if the condition is met I should repeat the http get request }) .subscribe() Is there a way to conditional repeat the http get request? Thanks, Marco 回答1: You can use expand operator. Here's an example: let request$ = http.get('url'); request$.expand(value => { return value !== 0 ? request$ : Rx

Limit throughput with RxJava

↘锁芯ラ 提交于 2019-12-22 05:49:45
问题 The case I'm into right now is quite hard to explain so I will write a simpler version just to explain the issue. I have an Observable.from() which emits a sequence of files defined by an ArrayList of files. All of these files should be uploaded to a server. For that I have an function that does the job and returns an Observable . Observable<Response> uploadFile(File file); When I run this code it gets crazy, the Observable.from() emits all of the files and they are uploaded all at ones, or

Using a F# event and asynchronous in multi-threaded code

断了今生、忘了曾经 提交于 2019-12-22 05:08:36
问题 I'm working a lot with asynchronous workflows and agents in F#. While I was going a little bit deeper into events I noticed that the Event<_>() type is not thread-safe. Here I'm not talking about the common problem of raising an event. I'm actually talking about subscribing and removing/disposing from an event. For testing purposes, I have written this short program: let event = Event<int>() let sub = event.Publish [<EntryPoint>] let main argv = let subscribe sub x = async { let mutable

Angular2 - Multiple dependent sequential http api calls

非 Y 不嫁゛ 提交于 2019-12-22 04:37:09
问题 I am building an Angular2 app and one of the components needs to make multiple API calls which are dependent on the previous ones. I currently have a service which makes an API call to get a list of TV shows. For each show, I then need to call a different API multiple times to step through the structure to determine if the show exists on a Plex server. The API documentation is here For each show, I need to make the following calls and get the correct data to determine if it exists: (Assume we

Best way to share an array between two components using a service in Angular2?

半腔热情 提交于 2019-12-21 23:19:30
问题 I'm developing an app in which there is a component (RecordSelectorComponent) where the user can select multiple records from a grid. The RecordSelectorComponent is nested in SharedAttributesComponents, which is nested in a WizardComponent, and that is nested in a ModalComponent. So the hierarchy looks like this: RecordSelector -(nested in)-> SharedAttributes -> Wizard -> Modal -> App I would like the RecordSelectorComponent to be able to share its list of selected records with the top-level

How to abort an Ajax request from an Observable?

北城以北 提交于 2019-12-21 21:14:03
问题 My code contains this simple function I'm using to upload files to my PHP server (there's an xhr request nested in an RxJS/Observable ): fileUpload(file: File): Observable<any> { return new Observable( observer => { let xhr:XMLHttpRequest = new XMLHttpRequest(); xhr.onreadystatechange = () => { if (xhr.readyState === 4) { if (xhr.status === 200) { observer.next(<any>JSON.parse(xhr.response)); } else { observer.error(xhr.response); observer.complete(); } } }; xhr.open('POST', '__BACKEND__

angular2 / RxJS - how to retry from inside subscribe()

老子叫甜甜 提交于 2019-12-21 17:35:13
问题 this is my code: this._api.getCompanies().subscribe( res => this.companies = JSON.parse(res), exception => {if(this._api.responseErrorProcess(exception)) { // in case this retured TRUE then I need to retry() } } ) in case an exception happened, it will be sent to a function in the API then return true if the problem is fixed (like token refreshed for example) and it just needs to retry again after its fixed I could not figure out how to make it retry. 回答1: In your .getCompanies() call right

Making polling request in Angular 2 using Observable

无人久伴 提交于 2019-12-21 09:07:47
问题 I have the following code to make a polling GET request in AngularJS 2: makeHtpGetRequest(){ let url ="http://bento/supervisor/info"; return Observable.interval(2000) .map(res => res.json()) //Error here .switchMap(() => this.http.get(url)); /* This portion works well return this.http.get(url) .map(res =>res.json());*/ } TypeScript is giving me an error make the response in JSON format (check comment in the code. TypeError: res.json is not a function Surprisingly, it was working for some time

'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

柔情痞子 提交于 2019-12-21 08:50:12
问题 I am trying to learn reactive programming using RxJS. I was trying to create an observable from an array using Observable.from() method, but I am getting an error: Property 'from' does not exist on type 'typeof Observable' I scaffolded an Angular application using Angular CLI, so all the dependencies including RxJS package was imported correctly. In app.component.ts I added below import statements: import { Observable} from 'rxjs/Observable' import 'rxjs/observable/from' And my AppComponent