Skip to content

Instantly share code, notes, and snippets.

@snippe
Last active August 29, 2015 14:09
Show Gist options
  • Save snippe/2713629999abd1586514 to your computer and use it in GitHub Desktop.
Save snippe/2713629999abd1586514 to your computer and use it in GitHub Desktop.
var isAsync = true;
function callWebService(){
console.log('Calling web service');
$.ajax({
url: "http://date.jsontest.com/",
async : isAsync
}).done(function (data) {
console.log(data);
});
}
function localFunc1(){
console.log('Calling local func1');
}
function localFunc2(){
console.log('Calling local func2');
}
$.when(localFunc1())
.then(callWebService)
.then(localFunc2);
//Output
//Calling local func1
//Calling web service
//Calling local func2
//Object {time: "05:24:04 AM", milliseconds_since_epoch: 1416029044010, date: "11-15-2014"}
//Output if async = false
//Calling local func1
//Calling web service
//Object {time: "05:24:04 AM", milliseconds_since_epoch: 1416029044010, date: "11-15-2014"}
//Calling local func2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment