Safe Haskell | None |
---|---|
Language | Haskell2010 |
Memoize the results of actions. In other words: actions will be run once, on demand, and their results saved.
Exceptions semantics: if a synchronous exception is thrown while performing
the computation, that result will be saved and rethrown each time
runMemoized
is called subsequently.'
Since: 0.2.8.0
Synopsis
- data Memoized a
- runMemoized :: MonadIO m => Memoized a -> m a
- memoizeRef :: MonadUnliftIO m => m a -> m (Memoized a)
- memoizeMVar :: MonadUnliftIO m => m a -> m (Memoized a)
Documentation
A "run once" value, with results saved. Extract the value with
runMemoized
. For single-threaded usage, you can use memoizeRef
to
create a value. If you need guarantees that only one thread will run the
action at a time, use memoizeMVar
.
Note that this type provides a Show
instance for convenience, but not
useful information can be provided.
Since: 0.2.8.0
runMemoized :: MonadIO m => Memoized a -> m a Source #
Extract a value from a Memoized
, running an action if no cached value is
available.
Since: 0.2.8.0
memoizeRef :: MonadUnliftIO m => m a -> m (Memoized a) Source #
Create a new Memoized
value using an IORef
under the surface. Note that
the action may be run in multiple threads simultaneously, so this may not be
thread safe (depending on the underlying action). Consider using
memoizeMVar
.
Since: 0.2.8.0
memoizeMVar :: MonadUnliftIO m => m a -> m (Memoized a) Source #
Same as memoizeRef
, but uses an MVar
to ensure that an action is
only run once, even in a multithreaded application.
Since: 0.2.8.0