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

Ouroboros.Consensus.Util.STM

Synopsis

Watcher

data Watcher (m ∷ TypeType) 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.

forkLinkedWatcherAllocate Source #

Arguments

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

Label for the thread

→ m r 
→ (r → m ()) 
→ (r → Watcher m a fp) 
→ m (Thread m Void) 

Spawn a new thread that safely allocates a resource, then runs a Watcher using the resource, finalizing the resource safely when the watcher terminates in any way.

The allocated resource and thread are both linked to the registry.

forkLinkedWatcherFinalize Source #

Arguments

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

Label for the thread

Watcher m a fp 
→ m () 
→ m (Thread m Void) 

Spawn a new thread that runs a Watcher, executing a finalizer when the thread terminates.

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 some value (without/only with an expensive Eq instance) changed.

Constructors

Fingerprint Word64 

Instances

Instances details
Enum Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

Generic Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

Associated Types

type Rep Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep Fingerprint = D1 ('MetaData "Fingerprint" "Ouroboros.Network.BlockFetch.ConsensusInterface" "ouroboros-network-api-0.16.0.0-dbea09ae17e8c2f2c2bf8a649e0cc50d623284bdb4c27b8da54203349b774799" 'True) (C1 ('MetaCons "Fingerprint" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Show Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

Eq Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

NoThunks Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep Fingerprint 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep Fingerprint = D1 ('MetaData "Fingerprint" "Ouroboros.Network.BlockFetch.ConsensusInterface" "ouroboros-network-api-0.16.0.0-dbea09ae17e8c2f2c2bf8a649e0cc50d623284bdb4c27b8da54203349b774799" '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 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

Methods

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

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

Generic (WithFingerprint a) 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

Associated Types

type Rep (WithFingerprint a) 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep (WithFingerprint a) = D1 ('MetaData "WithFingerprint" "Ouroboros.Network.BlockFetch.ConsensusInterface" "ouroboros-network-api-0.16.0.0-dbea09ae17e8c2f2c2bf8a649e0cc50d623284bdb4c27b8da54203349b774799" 'False) (C1 ('MetaCons "WithFingerprint" 'PrefixI 'True) (S1 ('MetaSel ('Just "forgetFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "getFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Fingerprint)))
Show a ⇒ Show (WithFingerprint a) 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

NoThunks a ⇒ NoThunks (WithFingerprint a) 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep (WithFingerprint a) 
Instance details

Defined in Ouroboros.Network.BlockFetch.ConsensusInterface

type Rep (WithFingerprint a) = D1 ('MetaData "WithFingerprint" "Ouroboros.Network.BlockFetch.ConsensusInterface" "ouroboros-network-api-0.16.0.0-dbea09ae17e8c2f2c2bf8a649e0cc50d623284bdb4c27b8da54203349b774799" 'False) (C1 ('MetaCons "WithFingerprint" 'PrefixI 'True) (S1 ('MetaSel ('Just "forgetFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "getFingerprint") 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Fingerprint)))

blockUntilAllJust ∷ ∀ (m ∷ TypeType) a. MonadSTM m ⇒ [STM m (Maybe a)] → STM m [a] Source #

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

Wait until the TVar changed

blockUntilJust ∷ ∀ (m ∷ TypeType) a. MonadSTM 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 ∷ TypeType) (m ∷ TypeType) Source #

Constructors

Sim 

Fields

simId ∷ ∀ (m ∷ TypeType). Sim (STM m) m Source #

simStateT ∷ ∀ (m ∷ TypeType) st (n ∷ TypeType). IOLike m ⇒ StrictTVar m st → Sim n m → Sim (StateT st n) m Source #

withTMVar

withTMVarIOLike m ⇒ StrictTMVar m a → (a → m (c, a)) → m c Source #

Apply f with the content of tv as state, restoring the original value when an exception occurs

withTMVarAnd Source #

Arguments

IOLike m 
StrictTMVar m a 
→ (a → STM m b)

Additional STM action to run in the same atomically block as the TMVar is acquired

→ (a → b → m (c, a))

Action

→ m c 

Apply f with the content of tv as state, restoring the original value when an exception occurs. Additionally run a STM action when acquiring the value.