An implementation of the mediator pattern for asynchronous events in Javascript