<div dir="ltr">Hi,<div>I am currently learning Haskell, and really enjoying it, thankyou to the community for this well considered language.</div><div>I have started using the async library, and I can't quite figure out some of the documentation, and I wonder if someone could help.</div><div><br></div><div><a href="https://hackage.haskell.org/package/async-2.2.2/docs/Control-Concurrent-Async.html#g:3">https://hackage.haskell.org/package/async-2.2.2/docs/Control-Concurrent-Async.html#g:3</a><br></div><div><br></div><div>Makes the comment that: "<span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif">This is a useful variant of </span><code style="font-size:13px;margin:0px;padding:0px;line-height:16.12px;color:rgb(0,0,0)"><a href="https://hackage.haskell.org/package/async-2.2.2/docs/Control-Concurrent-Async.html#v:async" title="Control.Concurrent.Async" style="margin:0px;padding:0px;text-decoration-line:none;color:rgb(171,105,84)">async</a></code><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif"> that ensures an </span><code style="font-size:13px;margin:0px;padding:0px;line-height:16.12px;color:rgb(0,0,0)">Async</code><span style="font-size:13px;color:rgb(0,0,0);font-family:sans-serif"> is never left running unintentionally." However, I can't see how I would use this.</span></div><div><br></div><div><font color="#000000" face="sans-serif">To make the example more concrete, I have a function that looks like this:</font></div><br><br>runNodeHwBridgeUdp :: NodeHwInterface -> NodeHwUdpConfig-> IO()<br>runNodeHwBridgeUdp (NodeHwInterface l0up l0down) config = do<br>  putStrLn "Starting Node bridge"<br><br>  -- Launch all the subprocesses:<br>  t0 <- async $  (runMsgUpReader hwBridgeSharedData l0up)<br>  t1 <- async $  (evalStateT (runUDPWriter hwBridgeSharedData) (initialUdpDispatchData timeUs) )<br>  t2 <- async $  (runUDPReader hwBridgeSharedData l0down)<br><br>  putStrLn "Created child processes. Waiting...."<br>  (a, is_exception) <- waitAnyCatchCancel [t0, t1, t2]<br><br>  case is_exception of<br>    Right _ -> do<br>            error "SHOULD NOT GET HERE"<br>    Left exception -> do<br>            case (fromException exception) of<br>              Just (ex :: HwDestroyException) -> do<br>                putStrLn $ "BRIDGE ENDING: >>>> GOOD: SHUTDOWN: " ++ show exception<br>              Nothing -> do<br>                  throwIO exception<br>  return ()<br><div><br></div><div><br></div><div>This process launches 3 child processes, and then waits on them. I launch this function as an async-process, and it would be really helpful if when I "cancel"ed it, it would also also cancelled the children, but I don't understand how I would structure that...</div><div><br></div><div>  t0 <- withAsync $  (runMsgUpReader hwBridgeSharedData l0up) $ \async -> do </div><div>         ????<br>  t1 <- withAsync $  (evalStateT (runUDPWriter hwBridgeSharedData) (initialUdpDispatchData timeUs) ) $ \async -> do <div>         ????</div>  t2 <- async $  (runUDPReader hwBridgeSharedData l0down) $ \async -> do <br></div><div>         ????</div><div><br></div><div>I feel like I must be missing something here. </div><div>I'd appreciate any input; many thanks for your time,</div><div><br></div><div><br></div><div><br></div><div>Mike</div><div><br></div><div><br></div></div>