0

Recent angular project has promise everywhere so I started to use async/await. Not sure this is just syntax thing.

The component and service both seem fine with it.

So even (click)="asyncFunc()" is also seemingly OK.

async asyncFunc() {
    this.data = await this.someService.asyncFun();
}

I want to know if anyone has experience with this.

Anything down the road that might be a problem? Just guessing here, maybe an async function kept waiting then that component or that service involved might become hard to die when route changes.

Hao
  • 6,291
  • 9
  • 39
  • 88
  • better to switch to observables instead as they are cancellable and you can kill them when required – mak15 Apr 27 '21 at 07:02

1 Answers1

0

To be honest, observables are a wonderful way to write reactive and clean code.

Async/Await is just syntactic sugar.

But no one can argue that async/await makes code more precise and readable.

It always dependends on your use case.

Check these:

Is it a good practice using Observable with async/await?

What is the difference between Promises and Observables?

jo-chris
  • 362
  • 6
  • 13