Open dcoutts opened 5 years ago
"timer" or "timeout"? Names names names.
In general I like it. However I think updateTimer
needs to be IO
, not STM
, right? There's no way to perform a transaction involving updateTimer
because the underlying API is IO
. Similarly cancelTimer
. Does that make the API less useful? You can't do a test-and-update or a test-and-cancel in the same transaction.
Would it be possible for updateTimer
and cancelTimer
to return whether or not they worked?
The stm package has the rather nice
registerDelay
API.https://hackage.haskell.org/package/stm-2.5.0.0/docs/Control-Concurrent-STM-TVar.html#v:registerDelay
This is nice, but we could provide a more extensive timer API, based on the underlying GHC timer API. The really nice thing about
registerDelay
is that being based on STM it is composable. We just need a bit more for use cases like network protocols where you need to be able to push back a timeout. Cancelling is also useful. The GHC timer API can do all these things.I would like to suggest and get feedback on the following API and implementation. If we go for it, it might be best to add to a new module
Control.Concurrent.STM.Timer
. I can make a PR based on feedback.API:
And implementation in terms of the GHC timeout manager (which is what
registerDelay
uses)Plus one handy derived utility