Async/await works with promises under the hood, so you need to return a promise from your delayTime function.
The Promise constructor accepts an executor function that is run synchronously (ie. immediately) with two callback functions as arguments: one to resolve the promise and another to reject the promise.
setTimeout and setInterval were added to JavaScript years before promises were widely understood, and are therefore not immediately compatible with promises: you need to "promisify" them.
To promisify a setTimeout expression you wrap it in a promise executor function and call the resolve callback function from inside the setTimeout callback .
const delayTime = (time) =>
new Promise((resolve) => setTimeout(() => {
console.log("run after:", time);
resolve();
}, time));
const runTime = async () => {
await delayTime(1000);
await delayTime(900);
};
runTime();
const delayTime = time => { return new Promise(resolve => { setTimeout(() => { console.log('run after:', time); resolve(); }, time); }); };setTimeout()andsetInterval()do not create a promise