hydra-node-0.21.0: The Hydra node
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Persistence

Description

Handles to save/load files across the hydra-node. We use a simple JSON encoding and two modes of operation to store things: Full and Incremental.

Synopsis

Documentation

data Persistence a m Source #

Handle to save and load files to/from disk using JSON encoding.

Constructors

Persistence 

Fields

  • save :: ToJSON a => a -> m ()
     
  • load :: FromJSON a => m (Maybe a)
     

createPersistence :: (MonadIO m, MonadThrow m) => FilePath -> m (Persistence a m) Source #

Initialize persistence handle for given type a at given file path.

data PersistenceIncremental a m Source #

Handle to save incrementally and load files to/from disk using JSON encoding.

Constructors

PersistenceIncremental 

Fields

  • append :: ToJSON a => a -> m ()
     
  • source :: FromJSON a => ConduitT () a (ResourceT m) ()

    Stream all elements from the file.

loadAll :: (FromJSON a, MonadUnliftIO m) => PersistenceIncremental a m -> m [a] Source #

Load all elements from persistence into a list. XXX: Deprecate this to avoid large memory usage.

createPersistenceIncremental :: forall a m. (MonadUnliftIO m, MonadThrow m, FromJSON a) => FilePath -> m (PersistenceIncremental a m) Source #

Initialize persistence handle for given type a at given file path.

This instance of PersistenceIncremental is "thread-safe" in the sense that it prevents loading from a different thread once one starts $sel:append:PersistenceIncrementaling through the handle. If another thread attempts to $sel:source:PersistenceIncremental (or loadAll) after this point, an IncorrectAccessException will be raised.