Last active
July 28, 2017 08:40
-
-
Save gskachkov/50196028075e4f4812826f164f66755b 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
var all = items => Promise.all(items); | |
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()); | |
}; | |
async function flow() { | |
let count = 0; | |
const [ value1, value2 ] = await all([asyncRandomNumbers(), asyncRandomNumbers()]); | |
if (value1 > value2) { | |
count = value1; | |
} else if (value2 > 1) { | |
count = value2; | |
} else { | |
count = await asyncRandomNumbers(); | |
} | |
const result = await getUsers(count); | |
console.table(result.results); | |
} | |
flow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment