1. 4
    Write Async Functions with the async/await Operators
    3m 28s

Write Async Functions with the async/await Operators

Share this video with your friends

Send Tweet

async / await should really be thought as a better way to use Promises reliably and safely with less chances of programming errors.

This lesson covers the fundamentals of annotating a function as async. An async function gets the chance to use the await keyword. This lesson covers the usages of these keywords.

Brendan Whiting
~ 6 years ago

I tried making a constructor function async, and typescript yelled at me. What’s the best practice when I have async operations inside of my constructor? Continue using .then(() => { … }) ? Refactor the async code somewhere else?

Basarat Ali Syedinstructor
~ 6 years ago

What’s the best practice when I have async operations inside of my constructor

Add an async init method e.g. new Foo().init().then and so on 🌹

Brendan Whiting
~ 6 years ago

This is inside of an Angular component, I don't explicitly call new Component(), the framework does it for me. Would I put this logic inside ngOnInit?

Basarat Ali Syedinstructor
~ 6 years ago

This is inside of an Angular component, I don't explicitly call new Component(), the framework does it for me. Would I put this logic inside ngOnInit?

That would work. However angular will not wait for for the promise chain to complete.

Brendan Whiting
~ 6 years ago

Good to know