Vibescript Showcase
Bounded fanout
Limit how many tasks run at once with max:.
Source
showcase/concurrency/bounded_fanout.vibe
# title: Bounded fanout
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Limit how many tasks run at once with max:.
# description: max: sets the task limit for this call. A value above the host limit returns an error.
# tags: concurrency, tasks, structured-concurrency, fanout, max
# vibe: 0.4
def enrich_id(record)
record[:id] * record[:id]
end
def run
records = [
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 }
]
squares = Tasks.map(records, max: 4, with: :enrich_id)
{
max_concurrency: 4,
batch_size: records.length,
squares: squares
}
end
Output
Press Run example to run this code.