@@ -9,6 +9,7 @@ import Network.Transport
9 , EndPointAddress
9 , EndPointAddress
10 , newEndPoint
10 , newEndPoint
12+import Control.Exception (throwIO)
12import Control.Concurrent (forkIO)
13import Control.Concurrent (forkIO)
13import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
14import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
@@ -17,9 +18,16 @@ import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
17-- Returns the address of the new end point.
18-- Returns the address of the new end point.
18spawn :: Transport -> (EndPoint -> IO ()) -> IO EndPointAddress
19spawn :: Transport -> (EndPoint -> IO ()) -> IO EndPointAddress
19spawn transport proc = do
20spawn transport proc = do
20− addr <- newEmptyMVar
21+ addrMVar <- newEmptyMVar
21 forkIO $ do
22 forkIO $ do
22− Right endpoint <- newEndPoint transport
23+ mEndPoint <- newEndPoint transport
23− putMVar addr (address endpoint)
24+ case mEndPoint of
24− proc endpoint
25+ Left err ->
26+ putMVar addrMVar (Left err)
28+ putMVar addrMVar (Right (address endPoint))
25− takeMVar addr
30+ mAddr <- takeMVar addrMVar
32+ Left err -> throwIO err
33+ Right addr -> return addr