Last active
July 28, 2017 08:41
-
-
Save gskachkov/305174fb4802be9162d33db2b7e79222 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async function asyncRandomNumbers() { | |
const response = await fetch('https://www.random.org/decimal-fractions/?num=1&dec=10&col=1&format=plain&rnd=new'); | |
return Number(await response.text()); | |
} | |
async function getUsers(count) { | |
const response = await fetch("https://randomuser.me/api/?results=10", { method: "GET" }); | |
return JSON.parse(await response.text()); | |
}; | |
function flow() { | |
Promise | |
.all([asyncRandomNumbers(), asyncRandomNumbers()]) | |
.then(([value1, value2]) => { | |
let count = 0; | |
if (value1 > value2) { | |
count = value1; | |
} else if (value2 > 1) { | |
count = value2; | |
} else { | |
return asyncRandomNumbers(); | |
} | |
return Promise.resolve(count); | |
}) | |
.then(value => getUsers(value)) | |
.then(users => console.table(users.results)); | |
} | |
flow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment