>>>>> doEvent f usDelay = forkIO $
>>>>> threadDelay usDelay
>>>>> doEvent f usDelay
>>>>> f
There's a missing 'do' here, right?
Yes - I said that in a later e-mail but it doesn't fix me violating my own peeve about non-functional code snippits on -cafe.
>> Infinite loop? yes, that is what you wanted. Memory gobbling? Why
>> would you think that?
> Why would I think that ?
> doEvent f usDelay = do forkIO $ threadDelay usDelay
> doEvent f usDelay
> f
Are you sure this isn't interpreted as:
doEvent f usDelay = do (forkIO $ threadDelay usDelay)
doEvent f usDelay
f
The full code I ran and thought we were talking about (more or less) is inline here. For clarity - yes I know they are different in that one executes 'f' before the first sleep and the other does not.
------------- START CODE -----------------
import Control.Concurrent
import Control.Monad (forever)
import System.IO (hFlush, stdout)
doEvent f usDelay = forkIO $ do
threadDelay usDelay
doEvent f usDelay
f
doEvent2 f usDelay = do
forkIO f
threadDelay usDelay
doEvent2 f usDelay
main = do doEvent func 1000000 >> forever (threadDelay maxBound)
main2 = do doEvent2 func 1000000 >> forever (threadDelay maxBound)
func = putStr "." >> hFlush stdout
----------------------- END CODE -------------------
I.e. just forking off processes that only does a delay, never even
getting to 'f'?
The version you referenced is a little weird but so long as you fix the indentation it should be fine (drop "forkIO $ f" to the next line).
Cheers,
Thomas