Build an event emitter
Create isolated ordered event channels with on, off, once, and unsubscribe behavior.Description
Requirements
The solution exports the required createEventEmitter API from the editable module.
Listener order works deterministically for the documented normal, boundary, and repeated-use scenarios.
Off works deterministically for the documented normal, boundary, and repeated-use scenarios.
Once works deterministically for the documented normal, boundary, and repeated-use scenarios.
Unsubscribe works deterministically for the documented normal, boundary, and repeated-use scenarios.
Mutation during emit works deterministically for the documented normal, boundary, and repeated-use scenarios.
Event isolation works deterministically for the documented normal, boundary, and repeated-use scenarios.
Mutation while emitting
The first listener removes the second listener during an emit
The current dispatch remains deterministic and later emits use the updated list
Dispatching from a snapshot separates current iteration from future subscriptions.
Constraints
Preserve subscription orderRemoving an unknown listener is a no-opDo not expose the internal listener collections
Hints
Hint 1
Map each event name to its own ordered collection.
Hint 2
Iterate over a snapshot so unsubscribe calls cannot skip or duplicate current listeners.
Hint 3
Wrap once listeners while retaining enough identity to remove them through off.