Created
April 17, 2018 15:33
-
-
Save deque-blog/0bb9b21f3d3cef49106ac98d091f300c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select :: IRequest req a => req a -> AsyncFetch req a | |
select req = AsyncFetch $ \cacheVar -> do | |
cache <- takeMVar cacheVar | |
case lookupCache req cache of | |
Just var -> do | |
putMVar cacheVar cache | |
pure var | |
Nothing -> do | |
var <- fetch req | |
putMVar cacheVar (insertCache req var cache) | |
pure var |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment