kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 9a620ba2f31238f03cd28f1da5ef3838d67e4e8a 54 lines 1.2 kB view raw
1import { EventEmitter } from "node:events"; 2 3const EVENTS = new EventEmitter(); 4EVENTS.setMaxListeners(100); 5 6export type EventPayload<T = unknown> = { 7 type: string; 8 data: T; 9 timestamp: string; 10}; 11 12export async function shutdownEventBus(): Promise<void> { 13 EVENTS.removeAllListeners(); 14} 15 16export async function publishEvent( 17 eventType: string, 18 data: unknown, 19): Promise<void> { 20 const payload: EventPayload = { 21 type: eventType, 22 data, 23 timestamp: new Date().toISOString(), 24 }; 25 26 try { 27 EVENTS.emit(eventType, payload); 28 } catch (error) { 29 console.error("Failed to publish event:", error); 30 throw error; 31 } 32} 33 34export async function subscribeToEvent<T>( 35 eventType: string, 36 handler: (data: T) => Promise<void>, 37): Promise<void> { 38 try { 39 EVENTS.on(eventType, async (payload: EventPayload<T>) => { 40 try { 41 await handler(payload.data); 42 } catch (error) { 43 console.error(`Error processing event ${eventType}:`, error); 44 } 45 }); 46 } catch (error) { 47 console.error("Failed to subscribe to event:", error); 48 throw error; 49 } 50} 51 52process.on("SIGTERM", () => { 53 shutdownEventBus().catch(console.error); 54});