tbox-0.0.0: Transactional variables with IO hooksSource codeContentsIndex
Control.Concurrent.TFile
Portabilitynon-portable (requires STM)
Stabilityexperimental
MaintainerPeter Robinson <thaldyron@gmail.com>
Contents
Data type
Construction
Operations
Description

A transactional variable that writes its content to a file on each update.

This module should be imported qualified.

Synopsis
data TFile a
newEmptyIO :: Binary a => FilePath -> IO (TFile a)
newIO :: Binary a => FilePath -> a -> IO (TFile a)
new :: Binary a => FilePath -> a -> AdvSTM (TFile a)
read :: TBox t a => t a -> AdvSTM (Maybe a)
write :: TBox t a => t a -> a -> AdvSTM ()
delete :: TBox t a => t a -> AdvSTM ()
isEmpty :: TBox t a => t a -> AdvSTM Bool
Data type
data TFile a Source

A transactional variable that writes its content to a file on each update.

  • The updated memory content of the TFile is not visible to other threads until the file has been written successfully.
  • If the TFile is "dirty", the content is (re)read from the file on the next read.
show/hide Instances
Construction
newEmptyIO :: Binary a => FilePath -> IO (TFile a)Source
Constructs an initially empty TFile that is marked dirty. That means, on the next read, the contents of the provided file (if it exists) will be loaded into the TFile.
newIO :: Binary a => FilePath -> a -> IO (TFile a)Source
new :: Binary a => FilePath -> a -> AdvSTM (TFile a)Source
Operations
read :: TBox t a => t a -> AdvSTM (Maybe a)Source

If the TBox is dirty, this retries the transaction and rereads the content using readIO in a separate thread. Otherwise it simply returns the result of readSTM.

Note: Depending on the implementation, careless use of setDirty and read in the same transaction might lead to nonterminating retry loops.

write :: TBox t a => t a -> a -> AdvSTM ()Source
Writes the new content.
delete :: TBox t a => t a -> AdvSTM ()Source
Deletes the content.
isEmpty :: TBox t a => t a -> AdvSTM BoolSource
Returns True iff the TBox is empty.
Produced by Haddock version 2.4.2