magic-wormhole-0.3.3: Interact with Magic Wormhole

Safe HaskellSafe
LanguageHaskell2010

MagicWormhole.Internal.Sequential

Description

Helpers for processing messages in sequence.

Synopsis
  • data Sequential counter item
  • sequenceBy :: (Hashable counter, Eq counter) => (a -> counter) -> counter -> STM (Sequential counter a)
  • insert :: (Ord counter, Enum counter, Hashable counter, Eq counter) => Sequential counter a -> a -> STM Bool
  • next :: (Enum counter, Eq counter, Hashable counter) => Sequential counter a -> STM a

Documentation

data Sequential counter item Source #

A thing that gets numbered items and then buffers them so you can read them in order without gaps.

"counter" is an Enum that is used to determine the ordering of the elements, and "item" is the type of the items themselves.

sequenceBy Source #

Arguments

:: (Hashable counter, Eq counter) 
=> (a -> counter)

How to rank items

-> counter

The expected rank of the first item

-> STM (Sequential counter a) 

Create a Sequential value for a series of item.

insert :: (Ord counter, Enum counter, Hashable counter, Eq counter) => Sequential counter a -> a -> STM Bool Source #

Insert an item into the sequence. It may only be drawn from the sequence with next when its counter is next one.

If the counter has already been past, don't insert it, since we'll never reach it. Instead return False.

next Source #

Arguments

:: (Enum counter, Eq counter, Hashable counter) 
=> Sequential counter a

How item are ordered in sequence

-> STM a

The next item

Get and remove the next item from the sequence. This will block until there is an item with the exact rank we are expecting.