Skip to content

Instantly share code, notes, and snippets.

@dumboluzz
Created August 9, 2022 03:12
Show Gist options
  • Save dumboluzz/a34f8157ba886d1510161964f9cb1577 to your computer and use it in GitHub Desktop.
Save dumboluzz/a34f8157ba886d1510161964f9cb1577 to your computer and use it in GitHub Desktop.
// time is the simulated fetch response time in milliseconds
const fakeFetch = (result, time) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(result);
}, time);
});
};
const getRandom = (min, max) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
await (async () => {
const user = await fakeFetch(
{ id: 69, name: "Tnecniv" },
getRandom(100, 500)
);
const comments = await fakeFetch(`${user.id}-comments`, getRandom(500, 1000));
const books = await fakeFetch(`${user.id}-books`, getRandom(500, 1000));
const cats = await fakeFetch(`${user.id}-cats`, getRandom(500, 1000));
const dogs = await fakeFetch(`${user.id}-dogs`, getRandom(500, 1000));
console.log(books, comments, cats, dogs);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment