Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Last active July 28, 2017 08:40
Show Gist options
  • Save gskachkov/50196028075e4f4812826f164f66755b to your computer and use it in GitHub Desktop.
Save gskachkov/50196028075e4f4812826f164f66755b to your computer and use it in GitHub Desktop.
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