cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Control.Concurrent.Concierge

Description

This module provides a utility for ordering concurrent actions via locks.

Synopsis

Documentation

data Concierge m lock Source #

At a Concierge , you can obtain a lock and enforce sequential execution of concurrent IO actions.

Back in the old days, hotel concierges used to give out keys. But after the cryptocurrency revolution, they give out locks. :) (The term lock is standard terminology in concurrent programming.)

newConcierge :: MonadSTM m => m ( Concierge m lock) Source #

Create a new Concierge that keeps track of locks.

atomicallyWith :: ( Ord lock, MonadIO m, MonadThrow m) => Concierge IO lock -> lock -> m a -> m a Source #

Obtain a lock from a Concierge and run an IO action.

If the same (equal) lock is already taken at this Concierge , the thread will be blocked until the lock becomes available.

The action may throw a synchronous or asynchronous exception. In both cases, the lock is returned to the concierge.

atomicallyWithLifted :: ( Ord lock, MonadSTM m, MonadThread m, MonadThrow n) => ( forall b. m b -> n b) -> Concierge m lock -> lock -> n a -> n a Source #

More polymorphic version of atomicallyWith .