Automatically cancel subscription
npm i auto-cancel-observable
or
yarn auto-cancel-observable
import { AutoCancelObservable } from 'auto-cancel-observable'
@AutoCancelObservable()
methodName(param1, param2) {
return this.http.get(`${url}?param1=${param1}¶m2=${param2}`)
}
...
this.methodName('X','Y')
.subscribe(data => ...) // do something with the data
Invoking methodName multiple times will cancel the previous http calls and only the last or latest http data will be streamed to the subscription.