conio
Safe HaskellNone
LanguageGHC2021

ConIO.Communication

Synopsis

Gate

newtype Gate Source #

A Gate is initially closed and can be opened with openGate.

Constructors

Gate (TMVar ()) 

waitGate :: MonadSTM m => Gate -> m () Source #

Wait for the Gate to open.

openGate :: MonadSTM m => Gate -> m () Source #

Open a Gate. You cannot close a Gate.

Switch

newtype Switch Source #

A Switch is either on or off.

Constructors

Switch (TVar Bool) 

waitSwitch :: MonadSTM m => Switch -> STM a -> m a Source #

Wait for the switch to turn on and execute the given STM at the same time.

Be mindful that Switch is only guaranteed to be on during the given STM action.

setSwitch :: MonadSTM m => Switch -> m () Source #

Turn on the Switch

unsetSwitch :: MonadSTM m => Switch -> m () Source #

Turn off the Switch

toggleSwitch :: MonadSTM m => Switch -> m () Source #

Toggle the Switch between on/off.

Variable

newtype Variable a Source #

A Variable holds some value in a concurrency-safe manner.

Constructors

Variable (TVar a) 

newVariable :: MonadSTM m => a -> m (Variable a) Source #

waitVariable :: MonadSTM m => (a -> Bool) -> Variable a -> m a Source #

Wait until the value within the Variable fulfills some condition

writeVariable :: MonadSTM m => Variable a -> a -> m () Source #

Write a value to the Variable. Keep in mind that you can do this within STM.

getVariable :: MonadSTM m => Variable a -> m a Source #

Get the value of the Variable. Keep in mind that you can do this within STM.

Slot

newtype Slot a Source #

A Slot is either empty or contains an a.

Constructors

Slot (TMVar a) 

newSlot :: MonadSTM m => a -> m (Slot a) Source #

Creates a new Slot filled with a.

newEmptySlot :: MonadSTM m => m (Slot a) Source #

Creates a new empty Slot.

takeSlot :: MonadSTM m => Slot a -> m a Source #

Takes the element from the Slot. Waits if there is no element. Afterwards, the Slot is empty.

tryTakeSlot :: MonadSTM m => Slot a -> m (Maybe a) Source #

Tries to take the element from the Slot. Does not wait for the Slot to be filled. Afterwards, the Slot is empty.

readSlot :: MonadSTM m => Slot a -> m a Source #

Reads the element from the Slot. Waits if there is no element. Afterwards, the Slot is not empty.

tryReadSlot :: MonadSTM m => Slot a -> m (Maybe a) Source #

Tries to read the element from the Slot. Does not wait for the Slot to be filled. Afterwards, the Slot is not empty.

putSlot :: MonadSTM m => Slot a -> a -> m () Source #

Puts an element into the slot if there is space. Waits until the Slot is empty to fill it.

tryPutSlot :: MonadSTM m => Slot a -> a -> m Bool Source #

Tries to put an element into the Slot if there is space. Returns whether the putting was successful.

Counter

newtype Counter Source #

A Counter stores an int.

Constructors

Counter (TVar Int) 

getCounter :: MonadSTM m => Counter -> m Int Source #

Get the current value of the Counter.

setCounter :: MonadSTM m => Counter -> Int -> m () Source #

Set the value of the Counter.

incrementCounter :: MonadSTM m => Counter -> m () Source #

Increment the Counter by one.

decrementCounter :: MonadSTM m => Counter -> m () Source #

Decrement the Counter by one.

Queue

newtype Queue a Source #

A Queue holds zero or more values.

Constructors

Queue (TChan a) 

popQueue :: MonadSTM m => Queue a -> m a Source #

Pop the first element of the Queue, removing it from the queue. Waits until an element is available.

peekQueue :: MonadSTM m => Queue a -> m a Source #

Get the first element of the Queue, not removing it from the queue. Waits until an element is available.

tryPopQueue :: MonadSTM m => Queue a -> m (Maybe a) Source #

Pop the first element of the Queue, removing it from the queue. Does not wait and returns immediately, if no element is available.

tryPeekQueue :: MonadSTM m => Queue a -> m (Maybe a) Source #

Get the first element of the Queue, not removing it from the queue. Does not wait and returns immediately, if no element is available.

pushQueue :: MonadSTM m => Queue a -> a -> m () Source #

Push an element to the back of the Queue.

isEmptyQueue :: MonadSTM m => Queue a -> m Bool Source #

Checks if the Queue is empty.