home/ atoms/ sonic-pi-time-state-sync

sync in Sonic Pi always blocks until a future Time State event is inserted

sync :key blocks the current thread until a new value is stored at that key via set or cue. Unlike get (which reads the last stored value), sync always waits for future insertions. The synced thread also inherits the logical time of the setting thread, enabling precise timing without drift. Values passed through set can be received by sync as its return value. This lets threads coordinate without polling.

Examples

in_thread do amp = sync :foo sample :ambi_lunar_land, amp: amp end sleep 2 set :foo, 0.5

Assessment

Use sync to trigger a sample exactly when another live_loop finishes its 8th beat. Explain the difference between get and sync.

“Note that `sync` always waits for _future events_ and that it will block the current thread waiting for a new event”
corpus · sonic-pi-built-in-tutorial · chunk 21