Last active
August 29, 2015 14:09
-
-
Save snippe/2713629999abd1586514 to your computer and use it in GitHub Desktop.
This file contains 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
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