function run() {
console.log("car is running...")
setInterval(() => {
console.log("very very fast..", new Date().toLocaleTimeString())
}, 1000)
}
function engageGear() {
return new Promise( (resolve, reject) => {
setTimeout( () => {
resolve("engaged to D.")
}, 3000)
})
}
function startEngine() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("engine started!")
}, 4000)
})
}
async function drive() {
console.log(1, "strating the engine...")
const res1 = await startEngine()
console.log(2, res1)
const res2 = await engageGear()
console.log(3, res2)
clearTimeout()
run()
}
drive()