Skip to content

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

@leftaroundabout

Description

@leftaroundabout

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions