cue broadcasts a named event and sync blocks until the next occurrence of that event
cue :name broadcasts a named heartbeat event to all threads. sync :name blocks the current thread until the next cue of that name arrives, then resumes with the logical time of the cue-sender, ensuring tight beat alignment. Unlike sleep, sync waits for an uncertain future event, correcting timing drift: a late-started thread that calls sync :tick snaps to the cue-sender’s timeline on arrival.
Examples
in_thread do loop do cue :tick sleep 1 end end
in_thread do loop do sync :tick sample :drum_heavy_kick end end
Assessment
Start two live_loops out of phase, then use sync to lock them together without stopping either. Explain what ‘inherits logical time’ means.