Correct Try…Catch Syntax Using Async/Await

It seems to be best practice not to place multiple lines of business logic in the try body Actually I’d say it is. You usually want to catch all exceptions from working with the value: try { const createdUser = await this.User.create(userInfo); console.log(createdUser) // business logic goes here } catch (error) { console.error(error) // from … Read more

Combination of async function + await + setTimeout

Your sleep function does not work because setTimeout does not (yet?) return a promise that could be awaited. You will need to promisify it manually: function timeout(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function sleep(fn, …args) { await timeout(3000); return fn(…args); } Btw, to slow down your loop you probably don’t want … Read more