/*
* simulate an ajax operation to fetch a customer profile
*/
function getUser (id) {
return Q.delay(1000)
.thenResolve({
id: id,
name: 'user ' + id,
twiterHandler: 'jfroma'
});
}
/*
* simulate an asynchronous fetch from twitter.com
*/
function getTweets (customer) {
return Q.delay(1000)
.thenResolve([{
message: 'I love Q and Promises/A+'
}]);
}
getUser(123)
.then(getTweets)
.then(function (tweets) {
tweets.forEach(function(t){
alert(t.message);
});
});
External resources loaded into this fiddle: