Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created August 30, 2011 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/1182234 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/1182234 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>setImmediate + jQuery Deferred</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function() {
function wrapSetImmediate(work, time) {
var def = $.Deferred();
msSetImmediate(function() {
def.resolve(work());
}, time);
return def;
}
$(document).ready(function() {
var wrapped1, wrapped2, wrapped3, wrapped4;
wrapped1 = wrapSetImmediate(function() { return 'foo '; }, 100);
wrapped2 = wrapSetImmediate(function() { return 'bar '; }, 200);
wrapped3 = wrapSetImmediate(function() { return 'baz '; }, 50);
wrapped4 = wrapSetImmediate(function() { return 'quux'; });
$.when(wrapped1, wrapped2, wrapped3, wrapped4).then(function(a, b, c, d) {
$("#container").text(a + b + c + d);
});
});
})();
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment