Skip to content

Instantly share code, notes, and snippets.

View westy92's full-sized avatar

Seth Westphal westy92

View GitHub Profile
@westy92
westy92 / QueuedCallback.js
Last active July 25, 2019 21:56
Queued Callback
/*
Sometimes you need to queue things up before a callback is available. This solves that issue.
Push any item(s) to an array.
Once you want to start consuming these items, pass the array and a callback to QueuedCallback().
QueuedCallback will overload array.push as your callback and then cycle through any queued up items.
Continue to push items to that array and they will be forwarded directly to your callback. The array will remain empty.
Compatible with all browsers and IE 5.5+.
*/