Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add well-typed thread-waiting action(s) #53

Open
leftaroundabout opened this issue Nov 6, 2016 · 1 comment
Open

Add well-typed thread-waiting action(s) #53

leftaroundabout opened this issue Nov 6, 2016 · 1 comment

Comments

@leftaroundabout
Copy link

leftaroundabout commented Nov 6, 2016

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?

@mithrandi
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants