# await
Resolve a Future or coroutine to its result value. Passes through non-future values unchanged.
## Syntax
await $expr
## Examples
# Await a Future returned by an async function def fetch-user {|id| @async [str "user-" $id] } let user [await [fetch-user 42]] echo $user # "user-42"
# Await a coroutine directly defcoro compute {|x| yield "working..." ($x * $x) } let result [await [compute 7]] echo $result # 49
# Await on plain values passes through unchanged [await 42] # → 42 [await "hello"] # → "hello" [await nil] # → nil [await true] # → true
# Await in a coroutine body (sequential async operations) defcoro process-order {|order-id| let user [await [fetch-user $order-id]] let items [await [fetch-items $order-id]] let total [await [calculate-total $items]] [str "Order " $order-id " for " $user ": $" $total] }
# Nested await [await [await 5]] # → 5
## Notes
- If the value is a Future that is already resolved: returns the result immediately
- If the value is a pending Future: yields the current coroutine and registers it as a waiter. The coroutine is resumed when the Future resolves
- If the value is a coroutine: resumes it synchronously and returns the result
- If the value is any other type: passes through unchanged
- `await` only suspends the current coroutine — it does not block the event loop
- `await` is distinct from `yield`: `await` waits for an external value, `yield` suspends for re-entry
## See Also
`async`, `defcoro`, `yield`