I want to debug a function that returns a promise and for that I need a sleep function. I found this one:
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
and it works when used outside of a promise. However when I want to use it in a promise, I get the error, that sleep was not found. This is my code:
async function f(filename) {
return new Promise((resolve, reject) => {
await sleep(1000);
/*
rest of function
*/
});
}