thyme icon indicating copy to clipboard operation
thyme copied to clipboard

Add well-typed thread-waiting action(s)

Open leftaroundabout opened this issue 7 years ago • 1 comments

The standard way to wait in the Haskell IO monad is threadDelay. This works reasonably well, but the type of this action is awkward – integer time in magic-number-micro–seconds. Surely there should be a variant of this with a properly-typed time argument. Since threadDelay is in base, but no suitable time-type, it would seem sensible to put it in a library that defines such a time type – like thyme!

I've just written the following wrapper for my dynamic-plot project (which still uses time though I think I want to switch to thyme soon):

waitTill :: UTCTime -> IO ()
waitTill t = do
   tnow <- getCurrentTime
   threadDelay . max 0 . round $ diffUTCTime t tnow
                                   * 1e+6 -- threadDelay ticks in microseconds

Are there any arguments against adding a module with such “waiter-actions” to thyme?

leftaroundabout avatar Nov 06 '16 22:11 leftaroundabout

https://hackage.haskell.org/package/time-units is an interesting related thing here.

mithrandi avatar Dec 13 '17 03:12 mithrandi