* Public initialization method that wraps the implementation
(...args: any[])
| 29 | * Public initialization method that wraps the implementation |
| 30 | */ |
| 31 | async initialize(...args: any[]): Promise<TState> { |
| 32 | logger.debug(`Initializing ${this.serviceName}`, { |
| 33 | wasInitialized: this.isInitialized, |
| 34 | hadPreviousState: !!this.currentState, |
| 35 | }); |
| 36 | this.emit("initializing"); |
| 37 | |
| 38 | try { |
| 39 | const state = await this.doInitialize(...args); |
| 40 | this.currentState = state; |
| 41 | this.isInitialized = true; |
| 42 | logger.debug(`${this.serviceName} initialized successfully`, { |
| 43 | stateKeys: state ? Object.keys(state as any) : [], |
| 44 | isNowInitialized: this.isInitialized, |
| 45 | }); |
| 46 | this.emit("initialized", state); |
| 47 | return state; |
| 48 | } catch (error: any) { |
| 49 | logger.debug(`Failed to initialize ${this.serviceName}:`, error); |
| 50 | if (this.listenerCount("error") > 0) { |
| 51 | this.emit("error", error); |
| 52 | } |
| 53 | throw error; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get current service state (shallow copy for immutability) |
nothing calls this directly
no test coverage detected