ouroboros-consensus-0.1.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Util.STM

Synopsis

Watcher

data Watcher m a fp Source #

Specification for a thread that watches a variable, and reports interesting changes.

NOTE: STM does not guarantee that wNotify will literally be called on every change: when the system is under heavy load, some updates may be missed.

Constructors

Watcher 

Fields

  • wFingerprint ∷ a → fp

    Obtain a fingerprint from a value of the monitored variable.

  • wInitialMaybe fp

    The initial fingerprint

    If Nothing, the action is executed once immediately to obtain the initial fingerprint.

  • wNotify ∷ a → m ()

    An action executed each time the fingerprint changes.

  • wReaderSTM m a

    The variable to monitor.

forkLinkedWatcher Source #

Arguments

∷ ∀ m a fp. (IOLike m, Eq fp, HasCallStack) 
ResourceRegistry m 
String

Label for the thread

Watcher m a fp 
→ m (Thread m Void) 

Spawn a new thread that runs a Watcher

The thread will be linked to the registry.

withWatcher Source #

Arguments

∷ ∀ m a fp r. (IOLike m, Eq fp, HasCallStack) 
String

Label for the thread

Watcher m a fp 
→ m r 
→ m r 

Spawn a new thread that runs a Watcher

The thread is bracketed via withAsync and linked.

We do not provide the Async handle only because our anticipated use cases don't need it.

Misc

newtype Fingerprint Source #

Simple type that can be used to indicate something in a TVar is changed.

Constructors

Fingerprint Word64 

Instances

Instances details
Enum Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Eq Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Show Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Generic Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Associated Types

type Rep FingerprintTypeType Source #

NoThunks Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Methods

noThunks ∷ Context → FingerprintIO (Maybe ThunkInfo) #

wNoThunks ∷ Context → FingerprintIO (Maybe ThunkInfo) #

showTypeOfProxy FingerprintString #

type Rep Fingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

type Rep Fingerprint = D1 ('MetaData "Fingerprint" "Ouroboros.Consensus.Util.STM" "ouroboros-consensus-0.1.0.0-inplace" 'True) (C1 ('MetaCons "Fingerprint" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))

data WithFingerprint a Source #

Store a value together with its fingerprint.

Instances

Instances details
Functor WithFingerprint Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Methods

fmap ∷ (a → b) → WithFingerprint a → WithFingerprint b Source #

(<$) ∷ a → WithFingerprint b → WithFingerprint a Source #

Eq a ⇒ Eq (WithFingerprint a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Show a ⇒ Show (WithFingerprint a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Generic (WithFingerprint a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Associated Types

type Rep (WithFingerprint a) ∷ TypeType Source #

NoThunks a ⇒ NoThunks (WithFingerprint a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

Methods

noThunks ∷ Context → WithFingerprint a → IO (Maybe ThunkInfo) #

wNoThunks ∷ Context → WithFingerprint a → IO (Maybe ThunkInfo) #

showTypeOfProxy (WithFingerprint a) → String #

type Rep (WithFingerprint a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.STM

type Rep (WithFingerprint a) = D1 ('MetaData "WithFingerprint" "Ouroboros.Consensus.Util.STM" "ouroboros-consensus-0.1.0.0-inplace" 'False) (C1 ('MetaCons "WithFingerprint" 'PrefixI 'True) (S1 ('MetaSel ('Just "forgetFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "getFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Fingerprint)))

blockUntilAllJustMonadSTM m ⇒ [STM m (Maybe a)] → STM m [a] Source #

blockUntilChanged ∷ ∀ m a b. (MonadSTM m, Eq b) ⇒ (a → b) → b → STM m a → STM m (a, b) Source #

Wait until the TVar changed

blockUntilJustMonadSTM m ⇒ STM m (Maybe a) → STM m a Source #

runWhenJust Source #

Arguments

IOLike m 
ResourceRegistry m 
String

Label for the thread

STM m (Maybe a) 
→ (a → m ()) 
→ m () 

Spawn a new thread that waits for an STM value to become Just

The thread will be linked to the registry.

Simulate various monad stacks in STM

newtype Sim n m Source #

Constructors

Sim 

Fields

simIdSim (STM m) m Source #

simStateTIOLike m ⇒ StrictTVar m st → Sim n m → Sim (StateT st n) m Source #