limited suspending on readChan possible?
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
participants (1)
-
Volker Stolz