Simon Marlow wrote:
> but they are needlessly complicated, in my opinion.  This offers the
> same functionality:
> 
> mask :: ((IO a -> IO a) -> IO b) -> IO b
> mask io = do
>   b <- blocked
>   if b
>      then io id
>      else block $ io unblock

How does forkIO fit into the picture? That's one point where reasonable
code may want to unblock all exceptions unconditionally - for example to
allow the thread to be killed later.

    timeout t io = block $ do
        result <- newEmptyMVar
        tid <- forkIO $ unblock (io >>= putMVar result)
        threadDelay t `onException` killThread tid
        killThread tid
        tryTakeMVar result

regards,

Bertram
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to