import BaseDiscoveryProvider from '@/services/discovery/providers/BaseDiscoveryProvider' ; import { EventEmitter } from 'events' ; event event event event abstract export default class DiscoveryService extends EventEmitter { constructor ( readonly provider ) { super ( ) ; if ( ! this . provider ) { throw new Error ( 'DiscoveryProvider must be provided.' ) ; } this . setupListeners ( ) ; } private setupListeners ( ) { this . provider . on ( 'loaded-clusters' , ( clusters ) => { this . emit ( 'loaded-clusters' , clusters ) ; } ) ; this . provider . on ( 'error' , ( error ) => { this . emit ( 'error' , error ) ; } ) ; this . provider . on ( 'loaded-environments' , ( environments ) => { this . emit ( 'loaded-environments' , environments ) ; } ) ; this . provider . on ( 'loaded-regions' , ( regions ) => { this . emit ( 'loaded-regions' , regions ) ; } ) ; } /**
     * Initiates loading of the clusters. Users of this API should listen for the
     * 'loaded-*' events since clusters may be loaded incrementally or on a timer/interval.
     * If clusters fail to load at any point, an 'error' event will be fired. It is the callers
     * responsibility to handle this error appropriately.
     */ public start ( ) { this . provider . start ( ) ; } }