|
Implementing computations with timeout: msg#00088lang.haskell.cafe
Hello What is the best way of doing an computation with a timeout? A naive implementation using two threads is easy to create - but what is the preferred solution? withTimeout :: forall a. Int -> IO a -> IO (Maybe a) withTimeout time fun = do mv <- newEmptyMVar tid <- forkIO (fun >>= tryPutMVar mv . Just >> return ()) forkIO (threadDelay time >> killThread tid >> tryPutMVar mv Nothing >> return ()) takeMVar mv btw How would I do the same with the new STM abstraction? - Einar Karttunen |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Unicode: Hugs vs GHC (again) was: Re: Some random newbie questions: 00088, Dimitry Golubovsky |
|---|---|
| Next by Date: | RE: Hugs vs GHC (again) was: Re: Some randomnewbiequestions: 00088, Simon Marlow |
| Previous by Thread: | RE: Hugs vs GHC (again) was: Re: Some random newbiequestionsi: 00088, Simon Marlow |
| Next by Thread: | Re: Implementing computations with timeout: 00088, Tomasz Zielonka |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |