Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request for a cachedIOWithSTM' #27

Open
Vlix opened this issue Jan 3, 2025 · 0 comments
Open

request for a cachedIOWithSTM' #27

Vlix opened this issue Jan 3, 2025 · 0 comments

Comments

@Vlix
Copy link

Vlix commented Jan 3, 2025

It's somewhat unfortunate you can't create the cached value inside the STM monad.

I have a situation where I need to inspect some TVars first before deciding whether to create a new Cached value, and the golden path is that it doesn't have to be created, so in general I will be creating unnecessary Cached values to then ignore them.

With the following tweak, it would be an easy addition, I feel.

-- >> New base for all other functions instead of 'cachedIOWith''
cachedIOWithSTM'
    :: (MonadIO t, MonadCatch t)
    => (UTCTime -> UTCTime -> Bool)
    -> (Maybe (UTCTime, a) -> t a)
    -> STM (Cached t a)
cachedIOWithSTM' isCacheStillFresh io = do
  cachedT <- newTVar Uninitialized
  pure . Cached $ do
    ...

-- >> Defined in terms of 'cachedIOWithSTM''
cachedIOWith' isCacheStillFresh io =
  liftIO . atomically $ cachedIOWithSTM' isCachedStillFresh io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant