RxJs Observable - does it discard totally interrupted HTTP requests?


#1

Let us consider a button that emits https requests using ANgular's @angular/http.

In my understanding of an Observable, each click o nthe button will take over and discard the previous click on the button.

I am mainly used to normal callbacks or promises. ANd all the HTTP requests will queue up in the network tab of the browser's console.

Yes/No question:
Will the http requests queue up in the network tab using angular's requests as an Observable? So 10 clicks means a long way for lal requests.

What is the mechanism? Is it an extension of the browser's API or are there ways to do the same using old Javascript?

Is there a way to achieve the same using promises and callbacks?

Thank you in advance.


#2

Here one says that abort is called on the XHR object. So it is probably true (but not 100% sure).

And with fetch(), which is not used with @angular/http, there is this way:

By the way, why isn't @angular/http using the fetch API as a choosable alternative?


#3

Yes; if you want to cancel previous (not yet complete) requests you can use .switchMap() (see here for an example).

It uses XMLHttpRequest under the hood.

You already do subscribe to observables with a callback... if you prefer promises, you can convert the observable by calling .toPromise() though.

The point of the http service is to abstract away such implementation details and wrap the requests in an observable; for the consumer it makes no difference which interface it uses internally. But you're of course free to use the native fetch() API instead.


closed #4

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.