2009/5/30 Cetin Sert <[email protected]> > Hi how could one implement a function in concurrent haskell that either > returns 'a' successfully or due timeout 'b'? > > timed :: Int → IO a → b → IO (Either a b) > timed max act def = do >
Something like (warning, untested code - no compiler atm). timed timeout act fallback = do res <- newEmptyMVar tid <- forkIO $ act >>= writeMVar res threadDelay timeout stillRunning <- isEmptyMVar res if stillRunning then killThread tid >> return fallback else takeMVar res -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
