import { ITiler } from "@here/harp-datasource-protocol" ; import { ConcurrentWorkerSet } from "./ConcurrentWorkerSet" ; import { WorkerBasedTiler } from "./WorkerBasedTiler" ; /**
 * Default concurrent tiler helper.
 *
 * A convenient singleton that maintains a separate [[ConcurrentWorkerSet]] for each bundle
 * requested. Provides easy access to  WorkerBasedTiler s for data sources.
  export class ConcurrentTilerFacade { /**
     * The URL containing a script to fall back (default) to when looking for worker sets
     * and tilers.
     */ static defaultScriptUrl : string = "./decoder.bundle.js" ; /**
     * The default number of workers.
     */ static defaultWorkerCount : number = 1 ; /**
     * Returns a  WorkerBasedTiler instance.
     *
     *  param tilerServiceType param scriptUrl param workerCount param workerConnectionTimeout static getTiler ( tilerServiceType , scriptUrl ? , workerCount ? , workerConnectionTimeout ? ) { const workerSet = this . getWorkerSet ( scriptUrl , workerCount , workerConnectionTimeout ) ; return new WorkerBasedTiler ( workerSet , tilerServiceType ) ; } param scriptUrl param workerCount param workerConnectionTimeout static getWorkerSet ( scriptUrl ? , workerCount ? , workerConnectionTimeout ? ) { if ( scriptUrl === undefined ) { scriptUrl = this . defaultScriptUrl ; } let workerSet = this . workerSets [ scriptUrl ] ; if ( workerSet === undefined ) { const workerConnectionTimeoutInMs = workerConnectionTimeout !== undefined ? workerConnectionTimeout * 1000 : undefined ; workerSet = new ConcurrentWorkerSet ( { scriptUrl , workerCount : workerCount ?? this . defaultWorkerCount , workerConnectionTimeout : workerConnectionTimeoutInMs } ) ; this . workerSets [ scriptUrl ] = workerSet ; } return workerSet ; } param scriptUrl static destroyWorkerSet ( scriptUrl ) { const workerSet = this . workerSets [ scriptUrl ] ; if ( workerSet !== undefined ) { workerSet . destroy ( ) ; delete this . workerSets [ scriptUrl ] ; } } /**
     * Destroys all managed [[ConcurrentWorkerSet]]s.
     */ static destroy ( ) { Object . keys ( this . workerSets ) . forEach ( name => { this . workerSets [ name ] . destroy ( ) ; } ) ; this . workerSets = { } ; } /**
     * Destroys this [[ConcurrentTilerFacade]] if all of the [[ConcurrentWorkerSet]]s are
     * terminated.
     */ static destroyIfTerminated ( ) { let allWorkerSetsTerminated = true ; Object . keys ( this . workerSets ) . forEach ( name => { if ( ! this . workerSets [ name ] . terminated ) { allWorkerSetsTerminated = false ; } } ) ; if ( allWorkerSetsTerminated ) { ConcurrentTilerFacade . destroy ( ) ; } } /**
     * The [[ConcurrentWorkerSet]] instances which are stored by the script URL.
     */ private static workerSets : { [ bundleUrl ] : ConcurrentWorkerSet ; } = { } ; }