I am trying to use switchMap to cancel any previous http calls in Angular2. The code is basically
var run = ():Observable<any> => {
var url = 'http://...'
return this._http.get(url)
.map(result => {
return var xmlData:string = result.text()
});
}
function pollTasks() {
return Observable.of(1)
.switchMap(() => run())
.map(res => res)
}
// caller can do subscription and store it as a handle:
let tasksSubscription =
pollTasks()
.subscribe(data => {
console.log('aa'+data)
});
and so I call the entire source several times in a row and receive several replies (i.e.: aa+data)
I was under the impression switchMap should cancel the previous calls.