QamoosTech
Programming FundamentalsRuntime and memoryIntermediate

Async / Await

PronunciationAY-sink uh-WAYT

Definition

Keywords that let you write code that waits for slow work, like a network call, in a simple top-to-bottom style.

Where you hear it

JavaScript, TypeScript, Python, and C# code, plus interviews.

Examples

  • Use await to wait for the database query to finish.
  • You forgot await, so you got a promise instead of the data.
  • Await the fetch call so the code reads the response before it renders the list.

Common mistake

Awaiting things one by one when they could run together. Independent calls can run in parallel.

Don't confuse with

Async / await is often mixed up with multithreading, but async/await handles waiting without blocking the thread, whereas multithreading runs multiple tasks on different threads at the same time.

Say it at work

  • In a meeting or chatCan we refactor this function to use async/await so it is easier to read?
  • In an email or ticketPlease wrap the API call in an async/await block to handle the response properly.