SyncDispatcher

class SyncDispatcher(accessLayer: DBAccessLayer)

Asynchronous sync dispatcher for DB-backed config caching.

This class manages a background thread that consumes a queue of SyncTasks, ensuring that config objects evicted from the in-memory cache are persisted to the database without blocking the main thread.

Typically used internally by DB-backed Yacla config loaders to provide write-behind caching and eventual consistency with minimal latency.

The dispatcher guarantees that all enqueued tasks are completed before shutdown.

Example usage:

val dispatcher = SyncDispatcher(myAccessLayer)
dispatcher.enqueue(SyncDispatcher.SyncTask("key", config, MyClass::class.java))
...
dispatcher.shutdownAndWait()

Constructors

Link copied to clipboard
constructor(accessLayer: DBAccessLayer)

Types

Link copied to clipboard
data class SyncTask(val key: String, val value: Any, val type: Class<*>)

A single sync/save operation, representing a config object to write back to the database.

Functions

Link copied to clipboard

Enqueues a SyncTask for asynchronous saving to the database.

Link copied to clipboard

Waits until all currently enqueued and active tasks are completed, then stops the worker thread. Blocks the caller until completion.