Key Terms
Async vs Sync
- Sync β tasks run sequentially, blocks execution flow
- Async β tasks run concurrently, non-blocking
Concurrency vs Parallelism
- Concurrency β multiple tasks run start and complete in overlapping time periods
- Parallelism β multiple tasks run simultaneously using multiple processors
- Event Loop (Python) or Task Scheduler (.NET) β used to manage async execution
Why?
- Improved application responsiveness
- Efficient handling of IO-bound operations
- Better utilization of hardware
- More scalable applications
Async/Await in C#
- Uses
async
and await
keywords
- Based on
Task
and Task<T>
for async operations
- A
Task
is a monad
- βA monad is just a monoid in the category of endofunctorsβ π€
- A functional grouping of returned data
- A
Task
represents something that happened on a different processor
Await in C#
- The
await
keyword waits for the boolean value of Task
to be true
- When that happens, the data of
Task
is unwrapped by the await
keyword
async
function can then return the data that has been unwrapped to its called