limited suspending on readChan possible?
Volker Stolz
stolz@I2.Informatik.RWTH-Aachen.DE
Thu, 25 Jan 2001 12:51:18 +0100
Hello everyone, I thought I´d return to more earthly issue than discovering
bugs in signal handlers etc. :)
I´ve been looking for a way to suspend on an empty channel for only a
limited time. So I came up with a solution which involves dupChan (which
is currently broken as stated in Meurig´s bug-report) and unGetChan:
> timedReadChan ch t = do
> dup <- dupChan ch
> mv <- newEmptyMVar
> forkIO (do
> msg <- readChan dup
> putMVar mv True
> )
> forkIO (do
> threadDelay t
> putMVar mv False
> )
> res <- takeMVar mv
> if res
> then do
> -- we discard dup and re-read from ch:
> msg <- readChan ch
> return (Just msg)
> else (return Nothing)
However, shouldn´t the dupChan be a space-leak par excellence? We end up
having no readers and keep adding new meesages to dup...
--
\usepackage[latin1]{inputenc}!
Volker Stolz * stolz@i2.informatik.rwth-aachen.de * PGP + S/MIME