diff --git a/src/atlasViewer/atlasViewer.constantService.service.ts b/src/atlasViewer/atlasViewer.constantService.service.ts index 99f66f51f5467cd36ac58ac70b5ec41406e05e87..88ccf6f51fcc49f3bd5371738d19187e38a80b11 100644 --- a/src/atlasViewer/atlasViewer.constantService.service.ts +++ b/src/atlasViewer/atlasViewer.constantService.service.ts @@ -23,6 +23,18 @@ export class AtlasViewerConstantsServices{ */ public nehubaLandmarkConstant = 1e-8 + private TIMEOUT = 4000 + + /** + * raceFetch + */ + public raceFetch = (url) => Promise.race([ + fetch(url), + new Promise((_, reject) => setTimeout(() => { + reject(`fetch did not resolve under ${this.TIMEOUT} ms`) + }, this.TIMEOUT)) + ]) + /* TODO to be replaced by @id: Landmark/UNIQUE_ID in KG in the future */ public testLandmarksChanged : (prevLandmarks : any[], newLandmarks : any[]) => boolean = (prevLandmarks:any[], newLandmarks:any[]) => { return prevLandmarks.every(lm => typeof lm.name !== 'undefined') && diff --git a/src/atlasViewer/atlasViewer.dataService.service.ts b/src/atlasViewer/atlasViewer.dataService.service.ts index c402f2e72ef2bdd62db433ca5fbd1f6ce4665c9f..b6bab52944cda297cb5897dab53f62942c29182f 100644 --- a/src/atlasViewer/atlasViewer.dataService.service.ts +++ b/src/atlasViewer/atlasViewer.dataService.service.ts @@ -34,14 +34,14 @@ export class AtlasViewerDataService implements OnDestroy{ private constantService : AtlasViewerConstantsServices ){ this.constantService.templateUrls.map(url => - fetch(url) - .then(res => res.json()) + this.constantService.raceFetch(url) + .then((res: Response) => res.json()) .then(json => new Promise((resolve, reject) => { if(json.nehubaConfig) resolve(json) else if(json.nehubaConfigURL) - fetch(json.nehubaConfigURL) - .then(res => res.json()) + this.constantService.raceFetch(json.nehubaConfigURL) + .then((res: Response) => res.json()) .then(json2 => resolve( Object.assign({}, json, { nehubaConfig: json2 }) )) diff --git a/src/atlasViewer/atlasViewer.urlService.service.ts b/src/atlasViewer/atlasViewer.urlService.service.ts index 523e916ca3a0460a099f8c9728b6d80e7dfae271..9087930a30aea98f5baf1fc04237c202d8241a73 100644 --- a/src/atlasViewer/atlasViewer.urlService.service.ts +++ b/src/atlasViewer/atlasViewer.urlService.service.ts @@ -2,7 +2,7 @@ import { Injectable } from "@angular/core"; import { Store, select } from "@ngrx/store"; import { ViewerStateInterface, isDefined, NEWVIEWER, getLabelIndexMap, SELECT_REGIONS, CHANGE_NAVIGATION, LOAD_DEDICATED_LAYER, ADD_NG_LAYER, PluginInitManifestInterface } from "../services/stateStore.service"; import { Observable,combineLatest } from "rxjs"; -import { filter, map, scan, distinctUntilChanged, takeWhile, takeLast } from "rxjs/operators"; +import { filter, map, scan, distinctUntilChanged, skipWhile, take } from "rxjs/operators"; import { getActiveColorMapFragmentMain } from "../ui/nehubaContainer/nehubaContainer.component"; import { PluginServices } from "./atlasViewer.pluginService.service"; import { AtlasViewerConstantsServices } from "./atlasViewer.constantService.service"; @@ -76,8 +76,8 @@ export class AtlasViewerURLService{ select('viewerState'), filter(state=>isDefined(state)&&isDefined(state.fetchedTemplates)), map(state=>state.fetchedTemplates), - takeWhile(fetchedTemplates => fetchedTemplates.length < this.constantService.templateUrls.length), - takeLast(1), + skipWhile(fetchedTemplates => fetchedTemplates.length !== this.constantService.templateUrls.length), + take(1), map(ft => ft.filter(t => t !== null)) ).subscribe(fetchedTemplates=>{ const searchparams = new URLSearchParams(window.location.search)