Вот вам несколько тасок с недавнего собеседования на позицию middle backend node.js(стек: nest.js, redis, mongodb, typeorm, rabbitmq, docker). Попробуйте свои силы, падаваны🧐
Суть задачек в том, чтобы исправить ошибки(если есть) в коде и описать примерно, что тут хотел сделать автор. Прошу к ознакомлению:
1.
async function timeOutWrapper<T>(func: () => Promise<T>): Promise<T | null> {
return await new Promise((resolve, reject) => {
console.log("Timer start");
const timeout = setTimeout(() => { console.log("Timeout"); resolve(null)); }, 100*1000};
func().then(result => {
console.log("Success");
resolve(result);
})
.catch(error => {
console.error("Error");
reject(error);
});
});
}2.
class HttpRequestMaker {
async request(): Promise<number> {
await new Promise((resolve) => setTimeout(resolve, 1000));
throw new Error('Something went wrong...');
}
}
const httpServer = new HttpRequestMaker();
try {
httpServer.request().then(console.log);
} catch (error: any) {
console.error(error.message);
}3.
new Promise(async () => {
throw new Error('message');
}).catch(console.error);Присоединяйтесь к нашему общему чату и Discord серверу :)