Skip to content

Instantly share code, notes, and snippets.

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