Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
GitHub.App.Token.Refresh
Synopsis
- class HasExpiresAt a where
- data Refresh a
- refreshing :: (MonadUnliftIO m, HasExpiresAt a) => m a -> m (Refresh a)
- getRefresh :: MonadIO m => Refresh a -> m a
- cancelRefresh :: MonadIO m => Refresh a -> m ()
Documentation
class HasExpiresAt a where Source #
Instances
HasExpiresAt AccessToken Source # | |
Defined in GitHub.App.Token.Refresh Methods expiresAt :: AccessToken -> UTCTime Source # |
refreshing :: (MonadUnliftIO m, HasExpiresAt a) => m a -> m (Refresh a) Source #
Run an action to (e.g.) generate a token and create a thread to refresh it
refreshing
will create an initial token and a thread that checks its
expires_at
on a loop. When it has expired, the action is used again to
replace the token.
ref <-refreshing
$generateInstallationToken
creds installationId
Use getRefresh
to access the (possibly) updated token.
for_ repos $ repo -> do
token <- getRefresh
makeSomeRequest token repo
If you can't rely on program exit to clean up this background thread, you can manually cancel it:
cancelRefresh
ref
getRefresh :: MonadIO m => Refresh a -> m a Source #
cancelRefresh :: MonadIO m => Refresh a -> m () Source #