
1 Sep
2004
1 Sep
'04
2:15 p.m.
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 -> ... Keean.