Code Flow Part 2 — RunSyncFunctions & Batch Syncer Lock
Why This Matters
RunSyncFunctions is the heart of SyncApp — it's the loop that executes every registered sync function on every cycle. Understanding how it uses the singular instance check and locks the batch syncer explains why concurrent syncs don't corrupt data.
What You'll Learn
- How RunSyncFunctions creates a singular instance and retrieves the list of registered sync functions
- Why the batch syncer is locked before sync functions run — it's a critical shared resource
- How the loop iterates over sync functions, checks the function name, and evaluates eligibility
- What the singular instance returns (yes/no): whether a function is eligible to run right now
- Why this design prevents two instances of the same sync function from running simultaneously
Watch Video
Lesson Summary
RunSyncFunctions is called on every SyncApp cycle. It first creates a singular instance — a per-function lock tracker. Then it locks the batch syncer (a critical shared resource — nothing else should write to it while syncing). It then loops over all registered sync functions, checks each function's name, and asks the singular instance: 'is this function eligible to run?' The singular instance says yes if no other instance of that function is currently running. This prevents a slow patient sync from being re-triggered before it completes, which would cause data corruption.