Skip to content

Commit fbdfdad

Browse files
committed
replace async with labelled variant
1 parent a8d2def commit fbdfdad

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

hydra-node/src/Hydra/Node/InputQueue.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Control.Concurrent.Class.MonadSTM (
99
readTQueue,
1010
writeTQueue,
1111
)
12-
import Control.Monad.Class.MonadAsync (async)
1312

1413
-- | The single, required queue in the system from which a hydra head is "fed".
1514
-- NOTE(SN): this probably should be bounded and include proper logging
@@ -43,7 +42,7 @@ createInputQueue = do
4342
modifyTVar' nextId succ
4443
, reenqueue = \delay e -> do
4544
atomically $ modifyTVar' numThreads succ
46-
void . async $ do
45+
void . asyncLabelled "input-queue-reenqueue" $ do
4746
threadDelay delay
4847
atomically $ do
4948
modifyTVar' numThreads pred

hydra-node/test/Hydra/BehaviorSpec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Control.Concurrent.Class.MonadSTM (
1414
writeTQueue,
1515
writeTVar,
1616
)
17-
import Control.Monad.Class.MonadAsync (MonadAsync (async), cancel, forConcurrently)
17+
import Control.Monad.Class.MonadAsync (cancel, forConcurrently)
1818
import Control.Monad.IOSim (IOSim, runSimTrace, selectTraceEventsDynamic)
1919
import Data.List ((!!))
2020
import Data.List qualified as List
@@ -1067,7 +1067,7 @@ simulatedChainAndNetwork initialChainState = do
10671067
nodes <- newLabelledTVarIO "sim-chain-nodes" []
10681068
nextTxId <- newLabelledTVarIO "sim-chain-next-txid" 10000
10691069
localChainState <- newLocalChainState (initHistory initialChainState)
1070-
tickThread <- async $ simulateTicks nodes localChainState
1070+
tickThread <- asyncLabelled "sim-chain-tick" $ simulateTicks nodes localChainState
10711071
pure $
10721072
SimulatedChainNetwork
10731073
{ connectNode = \draftNode -> do
@@ -1077,7 +1077,7 @@ simulatedChainAndNetwork initialChainState = do
10771077
, postTx = \tx -> do
10781078
now <- getCurrentTime
10791079
-- Only observe "after one block"
1080-
void . async $ do
1080+
void . asyncLabelled "sim-chain-post-tx" $ do
10811081
threadDelay blockTime
10821082
createAndYieldEvent nodes history localChainState $ toOnChainTx now tx
10831083
, draftCommitTx = \_ -> error "unexpected call to draftCommitTx"

hydra-node/test/Hydra/Model.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Control.Concurrent.Class.MonadSTM (
2626
modifyTVar,
2727
readTVarIO,
2828
)
29-
import Control.Monad.Class.MonadAsync (async, cancel, link)
29+
import Control.Monad.Class.MonadAsync (cancel, link)
3030
import Data.List (nub, (\\))
3131
import Data.List qualified as List
3232
import Data.Map ((!))
@@ -649,8 +649,8 @@ seedWorld seedKeys seedCP futureCommits = do
649649
let party = deriveParty hsk
650650
otherParties = filter (/= party) parties
651651
(testClient, nodeThread) <- lift $ do
652-
outputs <- newLabelledTQueueIO ("outputs-" <> shortLabel hsk)
653-
messages <- newLabelledTQueueIO ("messages-" <> shortLabel hsk)
652+
outputs <- newLabelledTQueueIO ("seed-world-outputs-" <> shortLabel hsk)
653+
messages <- newLabelledTQueueIO ("seed-world-messages-" <> shortLabel hsk)
654654
outputHistory <- newLabelledTVarIO "seed-world-output-history" []
655655
node <-
656656
createHydraNode
@@ -666,7 +666,7 @@ seedWorld seedKeys seedCP futureCommits = do
666666
seedCP
667667
testDepositPeriod
668668
let testClient = createTestHydraClient outputs messages outputHistory node
669-
nodeThread <- async $ labelThisThread ("node-" <> shortLabel hsk) >> runHydraNode node
669+
nodeThread <- asyncLabelled ("seed-world-node-" <> shortLabel hsk) $ runHydraNode node
670670
link nodeThread
671671
pure (testClient, nodeThread)
672672
pushThread nodeThread

hydra-node/test/Hydra/Model/MockChain.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Control.Concurrent.Class.MonadSTM (
1616
writeTQueue,
1717
writeTVar,
1818
)
19-
import Control.Monad.Class.MonadAsync (async, link)
19+
import Control.Monad.Class.MonadAsync (link)
2020
import Data.Sequence (Seq (Empty, (:|>)))
2121
import Data.Sequence qualified as Seq
2222
import Data.Time (secondsToNominalDiffTime)
@@ -99,10 +99,10 @@ mockChainAndNetwork ::
9999
UTxO ->
100100
m (SimulatedChainNetwork Tx m)
101101
mockChainAndNetwork tr seedKeys commits = do
102-
nodes <- newLabelledTVarIO "nodes" []
103-
queue <- newLabelledTQueueIO "chain-queue"
102+
nodes <- newLabelledTVarIO "mock-chain-nodes" []
103+
queue <- newLabelledTQueueIO "mock-chain-chain-queue"
104104
chain <- newLabelledTVarIO "mock-chain-state" (0 :: ChainSlot, 0 :: Natural, Empty, initialUTxO)
105-
tickThread <- async (labelThisThread "chain" >> simulateChain nodes chain queue)
105+
tickThread <- asyncLabelled "mock-chain-tick" (simulateChain nodes chain queue)
106106
link tickThread
107107
pure
108108
SimulatedChainNetwork

hydra-prelude/src/Hydra/Prelude.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module Hydra.Prelude (
5555
newLabelledEmptyTMVarIO,
5656
concurrentlyLabelled,
5757
concurrentlyLabelled_,
58+
asyncLabelled,
5859
raceLabelled,
5960
raceLabelled_,
6061
withAsyncLabelled,
@@ -75,7 +76,7 @@ import Control.Concurrent.Class.MonadSTM.TVar (TVar, readTVar)
7576
import Control.Exception (IOException)
7677
import Control.Monad.Class.MonadAsync (
7778
Async,
78-
MonadAsync (concurrently, race, withAsync),
79+
MonadAsync (async, concurrently, race, withAsync),
7980
)
8081
import Control.Monad.Class.MonadEventlog (
8182
MonadEventlog,
@@ -372,3 +373,6 @@ concurrentlyLabelled (lblA, mA) (lblB, mB) =
372373

373374
concurrentlyLabelled_ :: (MonadThread m, MonadAsync m) => (String, m a) -> (String, m b) -> m ()
374375
concurrentlyLabelled_ = (void .) . concurrentlyLabelled
376+
377+
asyncLabelled :: MonadAsync m => String -> m a -> m (Async m a)
378+
asyncLabelled lbl mA = async $ labelThisThread lbl >> mA

hydraw/app/Main.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module Main where
22

33
import Hydra.Prelude
44

5-
import Control.Monad.Class.MonadAsync (async)
65
import Hydra.Cardano.Api (NetworkId (..), NetworkMagic (..))
76
import Hydra.Network (Host, readHost)
87
import Hydra.Painter (Pixel (..), paintPixel, withClient, withClientNoRetry)
@@ -82,7 +81,7 @@ httpApp networkId key host req send =
8281
Just [x, y, red, green, blue] -> do
8382
putStrLn $ show (x, y) <> " -> " <> show (red, green, blue)
8483
-- \| spawn a connection in a new thread
85-
void $ async $ withClientNoRetry host $ \cnx ->
84+
void $ asyncLabelled "client-paint-pixel" $ withClientNoRetry host $ \cnx ->
8685
paintPixel networkId key host cnx Pixel{x, y, red, green, blue}
8786
send $ responseLBS status200 corsHeaders "OK"
8887
_ ->

0 commit comments

Comments
 (0)