diff options
| author | LLLL Colonq <llll@colonq> | 2025-09-16 03:24:26 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-09-16 03:24:26 -0400 |
| commit | 664d91dcba96fed6a8cc39a26d81a159bab458ba (patch) | |
| tree | 330f43a1939409c89fe74efac6fa4d0c6f5e4190 /fig-bus/src/Fig/Bus/Binary | |
| parent | d642561b841822829fc18a9225f46c7bba21e312 (diff) | |
fig-bus: Fix race condition
Diffstat (limited to 'fig-bus/src/Fig/Bus/Binary')
| -rw-r--r-- | fig-bus/src/Fig/Bus/Binary/Client.hs | 16 |
1 files changed, 7 insertions, 9 deletions
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 |
