/* bees.du -- Concurrent bee swarm using spawn and datastore Spawns a swarm of worker bees that increment a shared counter. Demonstrates: - spawn() for concurrent workers - datastore() for thread-safe shared state - increment() for atomic operations - Coordination across independent processes */ md = require("markdown") // Initialize the swarm datastore swarm = datastore("swarm") swarm.set("bees", 0) swarm.set("buzzes", 0) print("🐝 Spawning bee swarm...") // Spawn 10 busy bees for i = 1, 10 do spawn("worker.du", {bee_id = i, swarm = "swarm"}) end print("🐝 Swarm initialized. Waiting for bees to work...") sleep(2) // Check results bee_count = swarm.get("bees") buzz_count = swarm.get("buzzes") // use multi-line string w template to print results print(md.ansi(""" # Bee Report - Total bees spawned: {{spawn_count}} - Bees counted: {{bee_count}} - Total buzzes: {{buzz_count}} - Average buzzes per bee: {{buzz_count / bee_count}} """))