Revert "refactor: clarify debouncer function"

This reverts commit 577ed4dd4c.
This commit is contained in:
steve-chavez
2026-04-10 18:16:19 -05:00
committed by Steve Chavez
parent dd394d6f81
commit 96bbc86756
+6 -12
View File
@@ -117,19 +117,13 @@ init conf@AppConfig{configLogLevel, configDbPoolSize} = do
pool <- initPool conf observer pool <- initPool conf observer
initWithPool pool conf loggerState metricsState observer --{ stateSocketREST = sock, stateSocketAdmin = adminSock} initWithPool pool conf loggerState metricsState observer --{ stateSocketREST = sock, stateSocketAdmin = adminSock}
-- 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. simpleDebounce :: IO () -> IO (IO ())
makeDebouncer :: IO () -> IO (IO ()) simpleDebounce act = do
makeDebouncer action = do
flag <- newEmptyMVar flag <- newEmptyMVar
void $ forkIO $ forever $ do
let worker = forever $ do
takeMVar flag takeMVar flag
action act
pure (void $ tryPutMVar flag ())
let trigger = void $ tryPutMVar flag ()
void $ forkIO worker
pure trigger
initWithPool :: SQL.Pool -> AppConfig -> Logger.LoggerState -> Metrics.MetricsState -> ObservationHandler -> IO AppState initWithPool :: SQL.Pool -> AppConfig -> Logger.LoggerState -> Metrics.MetricsState -> ObservationHandler -> IO AppState
initWithPool pool conf loggerState metricsState observer = mdo initWithPool pool conf loggerState metricsState observer = mdo
@@ -139,7 +133,7 @@ initWithPool pool conf loggerState metricsState observer = mdo
<*> newIORef Nothing <*> newIORef Nothing
<*> newIORef SCPending <*> newIORef SCPending
<*> newIORef False <*> newIORef False
<*> makeDebouncer (retryingSchemaCacheLoad appState *> threadDelay 100000) -- 100ms cooldown <*> simpleDebounce (retryingSchemaCacheLoad appState *> threadDelay 100000) -- 100ms cooldown
<*> newIORef conf <*> newIORef conf
<*> mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime } <*> mkAutoUpdate defaultUpdateSettings { updateAction = getCurrentTime }
<*> myThreadId <*> myThreadId