JSFiddle - React, Tailwind, and code Playground
by johnc_22
HTML
<span id="result"></span>
JavaScript
ImChat = {};
ImChat.RetryQueue = function()
{
this._queue = [];
};
ImChat.RetryQueue.QueueItem = function(callback)
{
this.callbackMethod = callback;
this.params = Array.prototype.slice.call(arguments, 1);
};
ImChat.RetryQueue.prototype =
{
_dequeueItem :function()
{
return this._queue.shift();
},
_enqueueItem: function(queueItem)
{
this._queue.push(queueItem);
},
_replayQueue: function()
{
var queueItem = this._dequeueItem();
while(typeof queueItem !== "undefined" && queueItem !== null)
{
queueItem.callbackMethod.apply(this, queueItem.params);
queueItem = this._dequeueItem();
}
alert("queue empty");
}
};
function test1(a, b, c)
{
alert("test1: " + a + ", " + b + ", " + c);
};
function test2(a, b, c, d)
{
alert("test2: " + a + ", " + b + ", " + c + ", " + d);
};
function test3(a, b)
{
alert("test3: " + a + ", " + b);
};
jQuery(document).ready(function()
{
var retryQueue = new ImChat.RetryQueue();
retryQueue._enqueueItem(new ImChat.RetryQueue.QueueItem(test1, 1, 2, 3));
retryQueue._enqueueItem(new ImChat.RetryQueue.QueueItem(test2, 1, 2, 3, 4));
retryQueue._enqueueItem(new ImChat.RetryQueue.QueueItem(test3, 1, 2));
retryQueue._replayQueue();
});