Lesson 11: Async repositories
A blocking database call freezes an entire thread until the answer returns — under real load that means a choking server and a frozen screen. In this lesson we build an async repository: an interface that returns Task, and methods that wait on it with await without blocking anyone.
An async method is like a restaurant pager: instead of standing and waiting at the counter, you take the buzzer and go do other things — and when the meal is ready, it rings.
- Async repository
- A data-access contract whose methods all return Task<T> — so callers await results without blocking a thread.
- Task<T> — a promise of a result
- Returned immediately when an async method is called; the T value itself becomes available only when the work completes.
- await — waiting without blocking
- Suspends the method, frees the thread for other work, and resumes from that spot with the result when the Task completes.