github-app-token-0.0.3.0: Generate an installation access token for a GitHub App
Safe HaskellSafe-Inferred
LanguageGHC2021

GitHub.App.Token.Refresh

Synopsis

Documentation

class HasExpiresAt a where Source #

Methods

expiresAt :: a -> UTCTime Source #

Instances

Instances details
HasExpiresAt AccessToken Source # 
Instance details

Defined in GitHub.App.Token.Refresh

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 #