CodingSaves ~1 hour

Implement a pub/sub event emitter

Build a type-safe, production-grade event emitter for decoupled in-process communication.

The prompt

You are a software engineer implementing an event system. Build a typed pub/sub event emitter in [LANGUAGE] that supports: strongly typed event names and payloads (using TypeScript discriminated unions or equivalent), synchronous and asynchronous subscribers, once() method for one-time listeners, wildcard subscriptions, subscriber priority ordering, error isolation (one failing subscriber doesn't affect others), memory leak prevention (weak references or explicit cleanup, max listener count warning), unsubscribe by returned handle, and debug mode that logs all events. Include unit tests covering all features including async error isolation.

Language: [LANGUAGE]
Use case: [BROWSER EVENTS / NODE.JS / IN-MEMORY COMMUNICATION BETWEEN MODULES]

Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.

Want AI to fill this in for you?

Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.

Try it free →

More coding prompts