I am testing Async await in my angular application.
Here is the code:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
async main() {
await this.one();
await this.two();
await this.three();
}
async one() {
setTimeout(() => {
console.log('one finished');
}, 5000);
}
async two() {
setTimeout(() => {
console.log('two finished');
}, 1000);
}
async three() {
setTimeout(() => {
console.log('three finished');
}, 4000);
}
}
When I look into the console it's not appearing as intended.
It's appearing in order: two, three and one.
I need it to appear in order one, two and finally three.
How can I fix this?