[Haskell-cafe] Implementing tryReadMVar

MR K P SCHUPKE k.schupke at imperial.ac.uk
Wed Sep 1 10:15:22 EDT 2004

>tryReadMVar mv = do mc <- tryTakeMVar mv

The normal reason people want tryRead is to do something 
like unix's 'select' function, where you want to wait on
one of several signals...

In my opinion it is better to do this with a _single_
channel and have one thread taking from the channel,
whilst all sources of the 'events' write to the same 
channel... so the refactoring would be like:

data Event = Even1 | Event2 | Event3 ...

c <- newChan
forkIO (...)
a <- readChan c
case a of
	Event1 -> ...
	Event2 -> ...


More information about the Haskell-Cafe mailing list