Proposal: System.Timeout module for base

Einar Karttunen ekarttun at cs.helsinki.fi
Sun Jan 28 07:16:23 EST 2007


On 26.01 23:48, Peter Simons wrote:
> timeout :: Int -> IO a -> IO (Maybe a)
> timeout n f
>     | n <  0    = fmap Just f
>     | n == 0    = return Nothing
>     | otherwise = do
>         pid <- myThreadId
>         ex  <- fmap Timeout newUnique
>         handleJust (\e -> dynExceptions e >>= fromDynamic >>= guard . (ex ==))
>                    (\_ -> return Nothing)
>                    (bracket (forkIO (threadDelay n >> throwDynTo pid ex))
>                             (killThread)
>                             (\_ -> fmap Just f))

This seems broken on GHC with FFI.

The thread gets blocked on a FFI call that blocks forever and thus the
timeout exception is not delivered - if I remember things correctly.

- Einar Karttunen


More information about the Libraries mailing list