On 12 December 2005 10:09, Joel Reymont wrote: > While we are waiting for ghc 6.6, could the same effect be achieved > by launching the computation that writes to t with forkIO?
Certainly. registerTimeout is just an optimisation that avoids creating a new thread each time. Cheers, Simon > On Nov 29, 2005, at 12:00 PM, Simon Marlow wrote: > >> threadDelay is IO-only; there's no way to use threadDelay in an STM >> transaction. For example, if you want to wait for a TVar to go from >> Nothing to Just x with a timeout, you could do this: >> >> readOrTimeout :: TVar (Maybe a) -> Int -> STM (Maybe a) >> readOrTimeout t secs = do timeout <- registerTimeout secs >> let check_timeout = do >> b <- readTVar timeout >> if b then return Nothing else retry >> check_t = do >> m <- readTVar t >> case m of >> Nothing -> retry >> Just x -> return x >> atomically $ check_timeout `orElse` check_t _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe