[Async Function: fetchProjects()]
│
│ async → allows await inside
▼
try { … } catch { … } finally { … }
│
▼
[Await Promise] → sp.web.lists.getByTitle("Projects").items.get()
│
┌──────┴────────┐
▼ ▼
Promise resolves Promise rejects
│ │
▼ ▼
console.log(items) catch(error) → console.error(error)
│ │
└─────────┬─────────┘
▼
finally → console.log("Cleanup / Done")
---
Other related keywords/concepts:
- return → resolves Promise inside async
- throw → rejects Promise inside async
- Promise.all() → wait for multiple Promises in parallel
- Promise.race() → continues when first Promise settles
- Promise.allSettled() → get results of all Promises (success + failure)
Explanation:
-
async→ allowsawaitin function. -
await→ pauses until the Promise resolves or rejects. -
try/catch/finally→ handles success, failure, and cleanup. -
Promise.all/race/allSettled→ advanced scenarios with multiple Promises. -
return→ resolves Promise automatically;throw→ rejects Promise.
No comments:
Post a Comment