JQuery Queue unleashed

If you need a good way to get queues in javascript/typescript, i have been playing around with jquery.queue. Its suppose to be for transitions and animations but has lately been opened up for whatever you want (sort of). I was looking at getting a third party queue because of my monstrosity in the check in process like http://benalman.com/code/projects/jquery-message-queuing/examples/ajax/ but i didn’t want to use a third party library. I decided to ignore the warnings of ‘its for animation only’ and see how i could use it.

// Queue can be stored in an empty object like this or any other element.
var queuedObject = $({});

// You may have a collection of many items, or a recursive call to deal with a number of items
// that you wish to proces in an orderly way.
var unknownArray = [‘one’, ‘two’, ‘three’, ‘four’];
$.each(unknownArray, (i, item) => {
// We can either queue them in loop/recursion or send the queued functions all through.
queuedObject.queue(“nameOfOperation”, (next: Function) => {
// Add the logic you want the queued item to do, this could include a deffered object.
alert(‘Message: ‘ + item);

// Calling the next function removes the item from the queue and kicks off the next one.
next();
});
});
// This starts the queue going. You can use queuedObject.clearQueue() or queuedObject.stop() to clear/pause during operation.
queuedObject.dequeue(“nameOfOperation”);