# async
Define an asynchronous function that returns a Future.
## Syntax
Async functions are regular `def` functions with the `@async` decorator:
def name { |params|
@async
body
}
## Examples
# Basic async function def fetch-data {|url| @async set resp [http/get $url] return $resp } # Calling an async function returns a Future immediately set fut [fetch-data "https://api.example.com/data"] echo $fut # <future:pending> # Await the future to get the result set result [await $fut]
# Async function with multiple parameters def greet {|name greeting| @async [str $greeting " " $name "!"] } set fut [greet "World" "Hello"] # The coroutine runs on the event loop; # use [await] to get the result
# Nested async calls def inner {|x| @async ($x + 1) } def outer {|y| @async set inner-fut [inner $y] set result [await $inner-fut] ($result * 10) }
## Notes
- `@async` wraps the function body in a coroutine spawned on the event loop
- The caller receives a `Future` immediately — the body runs asynchronously
- Use `await` to wait for the result
- Async functions can `yield` internally (they are coroutines)
## See Also
`await`, `defcoro`, `yield`