refactor: remove usage of Control.Debounce

This change replaces usage of Control.Debounce in Logger with makeDebouncer function extracted from AppState to a new module PostgREST.Debounce.
This commit is contained in:
Michał Kłeczek
2026-04-10 12:22:08 -05:00
committed by Steve Chavez
parent f4fc29855e
commit 381e12efa2
4 changed files with 24 additions and 20 deletions
+1 -14
View File
@@ -62,6 +62,7 @@ import PostgREST.Config.Database (queryDbSettings,
queryRoleSettings)
import PostgREST.Config.PgVersion (PgVersion (..),
minimumPgVersion)
import PostgREST.Debounce (makeDebouncer)
import PostgREST.SchemaCache (SchemaCache (..),
querySchemaCache,
showSummary)
@@ -117,20 +118,6 @@ init conf@AppConfig{configLogLevel, configDbPoolSize} = do
pool <- initPool conf observer
initWithPool pool conf loggerState metricsState observer
-- Make a new debouncer action. An internal "worker" thread runs forever ensuring "action" runs when the "trigger" is called. The "action" is only executed once over a burst of calls.
makeDebouncer :: IO () -> IO (IO ())
makeDebouncer action = do
flag <- newEmptyMVar
let worker = forever $ do
takeMVar flag
action
let trigger = void $ tryPutMVar flag ()
void $ forkIO worker
pure trigger
initWithPool :: SQL.Pool -> AppConfig -> Logger.LoggerState -> Metrics.MetricsState -> ObservationHandler -> IO AppState
initWithPool pool conf loggerState metricsState observer = mdo