Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created April 17, 2018 15:33
Show Gist options
  • Save deque-blog/0bb9b21f3d3cef49106ac98d091f300c to your computer and use it in GitHub Desktop.
Save deque-blog/0bb9b21f3d3cef49106ac98d091f300c to your computer and use it in GitHub Desktop.
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