Run non-blocking code (like loading a file or waiting for a web request) without freezing your app.
⸻
🔧 async keyword
• Marks a method as asynchronous.
• It allows using await inside that method.
• It usually returns Task, Task<T>, or void (for event handlers).
publicasyncTaskDoSomethingAsync(){awaitTask.Delay(2000);// Imagine there's a mission of HTTP request need 2 seconds to complete. Non-blocking.Debug.Log("Done HTTP mission");}
⸻
🔧 await keyword
• Waits for a Task to finish, but doesn’t block the main thread.
• Resumes the method after the awaited task completes.
awaitTask.Delay(1000);// Delays for 1 second without freezing; Imitating HTTP request
⸻
🔹 Task and Task<T> — Represent Future Results
✅ Goal:
Run methods in the background, or represent operations that complete later.
⸻
🔹 yield — Generator Keyword
✅ Goal:
Create lazy iterators (one item at a time), useful for loops, state machines, or coroutines.
🧠 In Unity:
Unity’s IEnumerator coroutines (used with StartCoroutine) rely on yield: