mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
[CST-4880] Add fallback strategy for hanging server check cached requests
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router';
|
import { ActivatedRouteSnapshot, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router';
|
||||||
|
|
||||||
import { Observable } from 'rxjs';
|
import { interval, Observable, race } from 'rxjs';
|
||||||
import { map, tap } from 'rxjs/operators';
|
import { map, mergeMapTo, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RootDataService } from '../data/root-data.service';
|
import { RootDataService } from '../data/root-data.service';
|
||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
@@ -27,7 +27,11 @@ export class ServerCheckGuard implements CanActivateChild {
|
|||||||
route: ActivatedRouteSnapshot,
|
route: ActivatedRouteSnapshot,
|
||||||
state: RouterStateSnapshot): Observable<boolean> {
|
state: RouterStateSnapshot): Observable<boolean> {
|
||||||
|
|
||||||
return this.rootDataService.findRoot(false).pipe(
|
const uncachedCheck$ = this.rootDataService.findRoot(false);
|
||||||
|
// fallback observable used if the uncached one hangs and doesn't emit value
|
||||||
|
const cachedCheck$ = interval(200).pipe(mergeMapTo((this.rootDataService.findRoot())));
|
||||||
|
|
||||||
|
return race([uncachedCheck$, cachedCheck$]).pipe(
|
||||||
getFirstCompletedRemoteData(),
|
getFirstCompletedRemoteData(),
|
||||||
map((res: RemoteData<any>) => res.hasSucceeded),
|
map((res: RemoteData<any>) => res.hasSucceeded),
|
||||||
tap((hasSucceeded: boolean) => {
|
tap((hasSucceeded: boolean) => {
|
||||||
|
Reference in New Issue
Block a user