From 664d91dcba96fed6a8cc39a26d81a159bab458ba Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 16 Sep 2025 03:24:26 -0400 Subject: fig-bus: Fix race condition --- fig-bus/src/Fig/Bus/Binary/Client.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'fig-bus/src/Fig/Bus/Binary/Client.hs') diff --git a/fig-bus/src/Fig/Bus/Binary/Client.hs b/fig-bus/src/Fig/Bus/Binary/Client.hs index 39798cd..3ee9050 100644 --- a/fig-bus/src/Fig/Bus/Binary/Client.hs +++ b/fig-bus/src/Fig/Bus/Binary/Client.hs @@ -35,16 +35,14 @@ busClient loc@(host, port) onConn onData onQuit = do let cmds = Commands { subscribe = \ev -> do - () <- MVar.takeMVar lock - hPut h "s" - writeLengthPrefixed h ev - MVar.putMVar lock () + MVar.withMVar lock \_ -> do + hPut h "s" + writeLengthPrefixed h ev , publish = \ev d -> do - () <- MVar.takeMVar lock - hPut h "p" - writeLengthPrefixed h ev - writeLengthPrefixed h d - MVar.putMVar lock () + MVar.withMVar lock \_ -> do + hPut h "p" + writeLengthPrefixed h ev + writeLengthPrefixed h d } in ( do -- cgit v1.2.3