Sleep For A Bit In Async Code
function sleep(time) {
return new Promise((resolve) => {
setTimeout(resolve, time)
})
}async function fakeUserFetch(userId) {
# add half a second of "network" latency
await sleep(500)
const fakeResponse = {
id: userId,
email: "fake-email@example.com"
}
return Promise.resolve(fakeResponse)
}Last updated