Last active
July 5, 2021 14:43
-
-
Save jherr/abf6a8e957b8a1e865e51926a195c092 to your computer and use it in GitHub Desktop.
Decorator starting point
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
const delay = <T>(time: number, data: T): Promise<T> => | |
new Promise((resolve) => | |
setTimeout(() => { | |
resolve(data); | |
}, time) | |
); | |
class Users { | |
async getUsers() { | |
return await delay(1000, []); | |
} | |
async getUser(id: number) { | |
return await delay(50, { | |
id: `user:${id}`, | |
}); | |
} | |
} | |
(async function () { | |
const users = new Users(); | |
const user = await users.getUser(22); | |
console.log(`Got ${JSON.stringify(user)}`); | |
await users.getUser(42); | |
await users.getUsers(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment