Goal: Run periodic work, react to events, and coordinate background tasks.
Examples:
examples/integration/triggers_minimal.sdexamples/integration/concurrency_minimal.sdexamples/concurrency.sd (full demo)examples/triggers_demo.sd (full catalog)Deep dives: triggers.md, concurrency.md
task sense every 50ms {
let scan = lidar.read();
if scan.nearest_distance < 0.5 m {
emit ObstacleSeen;
}
}
Tasks run on a scheduler with optional priority (critical, high, low) and resource budgets.
Use them for control loops separate from one-shot behaviors.
event ObstacleSeen;
on ObstacleSeen {
wheels.stop();
}
Emit events from tasks or behaviors:
emit ObstacleSeen;
Handlers run when the event fires. Trace them at runtime:
spanda run examples/integration/triggers_minimal.sd --trace-triggers
For background work and message passing:
module comm.ping;
export fn tick() -> Int {
return 1;
}
robot ConcurrentRover {
behavior run() {
let ch = channel();
send(ch, 42);
select {
recv(ch) => wheels.stop();
};
spawn tick();
}
}
| Builtin | Purpose |
|---|---|
channel() |
Create a message channel |
send / recv |
Non-blocking message pass |
select |
Wait on first ready channel |
spawn fn() |
Queue background function call |
parallel { } |
Cooperative concurrent blocks |
Full demo: examples/concurrency.sd
spanda check examples/integration/triggers_minimal.sd
spanda run examples/integration/triggers_minimal.sd --trace-triggers
spanda check examples/integration/concurrency_minimal.sd
spanda run examples/integration/concurrency_minimal.sd --trace-scheduler
spanda run examples/concurrency.sd --trace-scheduler --trace-tasks
event LowBattery to your roboton LowBattery { wheels.stop(); }LowBattery when a stub condition is true (e.g. always once after 5 loop
iterations in simulation)