haxl-2.1.2.0: A Haskell library for efficient, concurrent, and concise data access.

Safe HaskellNone
LanguageHaskell2010

Haxl.Core.Fetch

Description

Implementation of data-fetching operations. Most users should import Haxl.Core instead.

Synopsis

Documentation

dataFetch :: (DataSource u r, Request r a) => r a -> GenHaxl u w a Source #

Performs actual fetching of data for a Request from a DataSource.

dataFetchWithShow :: (DataSource u r, Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> GenHaxl u w a Source #

Performs actual fetching of data for a Request from a DataSource, using the given show functions for requests and their results.

uncachedRequest :: forall a u w (r :: * -> *). (DataSource u r, Request r a) => r a -> GenHaxl u w a Source #

A data request that is not cached. This is not what you want for normal read requests, because then multiple identical requests may return different results, and this invalidates some of the properties that we expect Haxl computations to respect: that data fetches can be arbitrarily reordered, and identical requests can be commoned up, for example.

uncachedRequest is useful for performing writes, provided those are done in a safe way - that is, not mixed with reads that might conflict in the same Haxl computation.

if we are recording or running a test, we fallback to using dataFetch This allows us to store the request in the cache when recording, which allows a transparent run afterwards. Without this, the test would try to call the datasource during testing and that would be an exception.

cacheResult :: Request r a => r a -> IO a -> GenHaxl u w a Source #

Transparently provides caching. Useful for datasources that can return immediately, but also caches values. Exceptions thrown by the IO operation (except for asynchronous exceptions) are propagated into the Haxl monad and can be caught by catch and try.

cacheResultWithShow :: (Eq (r a), Hashable (r a), Typeable (r a)) => ShowReq r a -> r a -> IO a -> GenHaxl u w a Source #

Transparently provides caching in the same way as cacheResult, but uses the given functions to show requests and their results.

cacheRequest :: Request req a => req a -> Either SomeException a -> GenHaxl u w () Source #

Inserts a request/result pair into the cache. Throws an exception if the request has already been issued, either via dataFetch or cacheRequest.

This can be used to pre-populate the cache when running tests, to avoid going to the actual data source and ensure that results are deterministic.

performFetches :: forall u w. Int -> Env u w -> [BlockedFetches u] -> IO (Int, [IO ()]) Source #

Issues a batch of fetches in a RequestStore. After performFetches, all the requests in the RequestStore are complete, and all of the ResultVars are full.

performRequestStore :: forall u w. Int -> Env u w -> RequestStore u -> IO (Int, [IO ()]) Source #

type ShowReq r a = (r a -> String, a -> String) Source #

Show functions for request and its result.