const delayFunction = async () => {
const startTime = new Date().getTime();
const duration = 10000;
console.log('START')
while (new Date().getTime() - startTime < duration) {
// this loop runs for 10 seconds
}
console.log('STOP');
};
const starterFunction = async () => {
console.log('1');
delayFunction();
console.log('2');
return 'DONE'
};
console.log(starterFunction())
so now I want an output as below:
1
2
DONE
START
STOP
If anyone knows how to achieve this with asynchronous programming please help me with this.
I tried creating a new promise and tried to execute the code inside it but even that dosent seem to be working.
const delayFunction = async () => {
return new Promise((resolve,reject) => {
const startTime = new Date().getTime();
const duration = 10000;
console.log('START')
while (new Date().getTime() - startTime < duration) {
// this loop runs for 10 seconds
}
resolve(console.log('STOP'));
});
};