I'll need your help to name or identify existing pattern like that. For the application I'm developing I need to create a queue of callbacks which are fired by an event. Once an event is triggered, consecutive callbacks that are added to the queue are fired immediately.
In the code it would like like that:
var queue = new TriggeredCallbackQueue();
queue.onTriggerOrNow(() => console.log('Callback 1'));
// Nothing is logged to the console
queue.onTriggerOrNow(() => console.log('Callback 2'));
// Nothing is logged to the console
queue.trigger(); // 'Callback1' and 'Callback 2' are logged to console
queue.onTriggerOrNow(() => console.log('Callback 3'));
// 'Callback 3' is logged to the console
queue.onTriggerOrNow(() => console.log('Callback 4'));
// 'Callback 4' is logged to the console
Do you know if such pattern already exists and is classified anywhere? How would you name it? What do you think about TriggeredCallbackQueue name?
Aucun commentaire:
Enregistrer un commentaire