Developer docs / AI Fabric tutorials
Fire-and-forget fan-out with spawn_map
- Batch / map
- Async job
Take it for a spin
The whole program in one file, ready to run.
import bladekit
app = bladekit.app("spawn-map")
@app.function(image="fabric/base", timeout=120)
def square(x: int) -> int:
return x * x
@app.local_entrypoint()
def main():
items = list(range(8))
# spawn_map returns a MapHandle at once; nothing is awaited here.
handle = square.spawn_map(items)
print(f"Fan-out launched: {handle.map_id}")
# Non-blocking: the batch is already running server-side, so we can poll
# its status before we ever ask for results.
print(handle.status()["outcome_counts"])
# ... do other work while the fleet churns through the batch ...
# Collect results whenever you're ready (order preserved by default).
results = list(handle.results(return_exceptions=True))
print(f"Squares: {results}")Run it
- Save as
spawn_map.py.square.spawn_map(items)creates the batch, pushes every input, and finalizes it server-side, then returns aMapHandleimmediately. - Unlike
.map()(which blocks and streams results as they land),spawn_mapnever blocks: you get the handle and get on with other work. - Collect later with
handle.results(order=..., return_exceptions=...), check progress withhandle.status(), or stop it withhandle.cancel(). - The batch is durable server-side, so the handle survives a client disconnect. Re-attach from any process with
blade map resume <map_id>. - Use
spawn_starmapwhen each element is a tuple of positional args:(a, b)maps tof(a, b).
Concepts used: Run, Async job