Skip to content

Instantly share code, notes, and snippets.

@jherr
Last active July 5, 2021 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jherr/abf6a8e957b8a1e865e51926a195c092 to your computer and use it in GitHub Desktop.
Save jherr/abf6a8e957b8a1e865e51926a195c092 to your computer and use it in GitHub Desktop.
Decorator starting point
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