Last active
August 29, 2015 13:56
-
-
Save jmcorpdev/8847923 to your computer and use it in GitHub Desktop.
queue sync or async function. You can put sleep between the functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function queue() { | |
var i = 0, | |
arr = arguments; | |
(function next() { | |
var args = arguments; | |
if (i < arr.length) { | |
var func = arr[i++]; | |
var funcArgs = [].concat(next, [].slice.call(args)); | |
if (!isNaN(func)) setTimeout(function () { | |
arr[i++].apply(this, funcArgs) | |
}, func); | |
else { | |
func.apply(this, funcArgs); | |
} | |
} | |
})(); | |
} | |
queue( | |
function (next) { | |
$.ajax(document.location.href, { | |
success: function (data, textStatus, jqXHR) { | |
next(data, textStatus, jqXHR); | |
} | |
}); | |
}, | |
function (next, data, textStatus, jqXHR) { | |
// do stuff after the jquery ajax call and get the params pass to the "next" callback in the previous function | |
next(); | |
}, | |
500, //sleep | |
function (next) { | |
// do stuff after 500ms | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment