# Async
`deft/stdext/async` provides fan-out helpers over the language's
`@async` / `await` futures. Each future already runs concurrently on the
event loop or its own thread (`deftask`, `defworker`, `sqlite/*-async`,
`os/run-async`); these helpers start a batch and collect the results in
order.
import "deft/stdext/async" as async from "deft/stdext/async" import @{ await-all map-concurrently }
## API
| Def | Signature | Description |
|---|---|---|
| `await-all` | `{| futures |}` | Resolve every future in order, returning results positionally; non-futures pass through |
| `map-concurrently` | `{| items fn |}` | Call `fn` on every item concurrently (each call becomes a future), then `await-all` |
| `each-concurrently` | `{| items fn |}` | Same fan-out for side effects; results are discarded |
| `filter-futures` | `{| items |}` | Keep only the Future values in a mixed list |
set results [$urls |> async/map-concurrently { fetch-data $it }] set futures [map $urls { [fetch-data $it] }] set results [await-all $futures] [async/each-concurrently $urls { log/info "fetched " [await [fetch-data $it]] }]
## Semantics
There is no pool: concurrency comes from the futures themselves, and
`await-all` simply joins in positional order. Error semantics are the
natives' — a `deftask` body that throws resolves with the error string
instead of rethrowing at `await`.
## See Also
- Concurrency — `deftask` / `await` fundamentals
- Tasks — streams, `future-ready?`, `task/stream-*`
- defworker — persistent worker runtimes