I have an authentication token that I know expires at a particular moment
in time:
type alias AuthState =
{ loggedIn : Bool
, permissions : List String
, expiresAt : Maybe Date
}
I would like to fire an event once it gets close to 'expiresAt'.
What happens if I update the subscription
subscriptions : Model -> Sub Msg
subscriptions model =
Time.every ((Date.toTime model.authState.expiresAt) - now) RefreshTokenMsg
I'm worried that as this subscription will be re-evaluated every time the
model changes, that Time.every may somehow miss this expiry time. Say there
are some other events causing model changes very close to the expiry time,
can re-evaluation this subscription cause a one off firing of it to be
missed?
Is there some better way to subscribe to a one-off event?
Or perhaps I should change the logic so once a point in time is passed that
is close to the expiry time, I start regularly firing RefreshTokenMsg,
perhaps every couple of secods. That way any glitches will be recovered
from:
subscriptions : Model -> Sub Msg
subscriptions model =
if afterCloseToExpiryTime then
Time.every Time.second RefreshTokenMsg
else
Sub.none
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.