| 113 | } |
| 114 | |
| 115 | class LocalPubSubChannel<T> implements PubSubChannel<T> { |
| 116 | private emitter = new EventEmitter() |
| 117 | |
| 118 | constructor(private config: PubSubChannelConfig) { |
| 119 | this.emitter.setMaxListeners(100) |
| 120 | logger.info(`${config.label}: Using process-local EventEmitter (Redis not configured)`) |
| 121 | } |
| 122 | |
| 123 | publish(event: T): void { |
| 124 | this.emitter.emit(this.config.channel, event) |
| 125 | } |
| 126 | |
| 127 | subscribe(handler: (event: T) => void): () => void { |
| 128 | this.emitter.on(this.config.channel, handler) |
| 129 | return () => { |
| 130 | this.emitter.off(this.config.channel, handler) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | dispose(): void { |
| 135 | this.emitter.removeAllListeners() |
| 136 | logger.info(`${this.config.label} local pub/sub disposed`) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | export function createPubSubChannel<T>(config: PubSubChannelConfig): PubSubChannel<T> { |
| 141 | const redisUrl = env.REDIS_URL |
nothing calls this directly
no outgoing calls
no test coverage detected