Skip to content

Instantly share code, notes, and snippets.

@thorstenweber83
Last active August 15, 2016 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thorstenweber83/5175be3b97c962e2488ef08d2c6f4bc6 to your computer and use it in GitHub Desktop.
Save thorstenweber83/5175be3b97c962e2488ef08d2c6f4bc6 to your computer and use it in GitHub Desktop.
Exercise 37: Sequencing HTTP requests with Observable: async await version
// this is an implementation of exercise 37 of
// http://reactivex.io/learnrx/
// to compare with the Observable implementation
// i assume that getJSON returns a Promise instead of an Observable...
function load(){
return new Promise(function(resolve,reject){
window.onload = resolve;
});
}
function(window, getJSON, showMovieLists, showError) {
async function processMovieLists(){
try{
const abTestInformation = await getJSON("http://api-global.netflix.com/abTestInformation");
const results = await Promise.all([
getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/config"),
getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/movieLists"),
]);
const config = results[0];
const movieListsMessage = results[1];
const copyOfMovieLists = Object.create(movieListsMessage.list);
if(config.showInstantQueue){
const queueMessage = await getJSON("http://api-global.netflix.com/" + abTestInformation.urlPrefix + "/queue");
const queue = queueMessage.list;
copyOfMovieLists.push(queue);
}
await load();
showMovieLists(copyOfMovieLists);
}
catch(err){
showError(err);
}
}
processMovieLists();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment