canceler.ts 414 B

123456789101112131415
  1. import { MonoTypeOperatorFunction } from 'rxjs';
  2. import { finalize } from 'rxjs/operators';
  3. import { BackendSrv } from 'app/core/services/backend_srv';
  4. export function cancelNetworkRequestsOnUnsubscribe<T>(
  5. backendSrv: BackendSrv,
  6. requestId: string | undefined
  7. ): MonoTypeOperatorFunction<T> {
  8. return finalize(() => {
  9. if (requestId) {
  10. backendSrv.resolveCancelerIfExists(requestId);
  11. }
  12. });
  13. }