[Haskell-cafe] Running an action periodically

Erèbe nemesia.lilith at gmail.com
Sat Nov 25 23:37:43 UTC 2017


Hello Moritz,

Indeed, the auto-update do not do any refresh if the returned action is not
called.
So in your case your token will expire, which is not the desired behavior.

>From the same package, you have Reaper
https://hackage.haskell.org/package/auto-update-0.1.4/docs/Control-Reaper.html
which allow you to run periodically an action on an associated resource
while still providing the possibility to read and append from this resource.

In your case it should fit by using the clean action as the refresh job,
and using reaperRead to get your token.
While this being said, using reaper may be a bit far fetched so using
async-refresh or pollT may be a better call :)


2017-11-25 23:53 GMT+01:00 Moritz Schulte <mtesseract at silverratio.net>:

> Hi Erèbe,
>
> Thanks for the suggestion.
>
> I've only had a very quick look at the auto-update package, so please
> correct me if I'm wrong. But I think there is an important difference
> between auto-update and the suggested pollT (or the async-refresh
> package):
>
> auto-update does not completely decouple the execution of the IO
> action from the calling thread. I'm referring to this comment:
>
>    mkAutoUpdate :: UpdateSettings a -> IO (IO a)
>
>    Generate an action which will either read from an automatically
>    updated value, **or run the update action in the current thread**.
>
> pollT and async-refresh are implemented such that the caller really
> only retrieves the result of a previously executed IO action.  Thus
> even if the IO action might block, the caller does basically not block
> (more than required for reading a TVar).
>
> For the use case it was created for (refreshing of authentication
> tokens in a micro service) it might be very important that the
> required tokens are *always* guaranteed to be available already at the
> time a request needs to be made.
>
> But maybe I'm overlooking something and auto-update does indeed also
> provide this functionality.
>
> Best,
> Moritz
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171126/bac0d664/attachment.html>


More information about the Haskell-Cafe mailing list