Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type EnumBounded t = (Ord t, Enum t, Bounded t)
- data Q a = Q [a] [a] !Int
- emptyQ :: Q a
- singletonQ :: a -> Q a
- snocQ :: a -> Q a -> Q a
- normalizeQ :: Q a -> Q a
- deleteQ :: Eq a => a -> Q a -> Q a
- popQ :: Q a -> Maybe (a, Q a)
- sizeQ :: Q a -> Int
- peekQ :: Q a -> Maybe a
- dropQ :: Q a -> Q a
- type Prio = Int
- applyPrios :: Ord t => [(t, Prio)] -> Map t Prio -> Map t Prio
- data Queue t a = Queue {
- queueData :: Vector (TVar (Q a))
- queueIndices :: Map t Int
- queuePrios :: Map t Prio
- defaultPrios :: EnumBounded t => Map t Prio
- newQueue :: EnumBounded t => Map t Prio -> IO (Queue t a)
- addQueue :: Ord t => t -> a -> Queue t a -> STM ()
- deleteQueue :: (Eq a, Ord t) => t -> a -> Queue t a -> STM ()
- debugDumpQueue :: (Enum t, Bounded t, Ord t) => Queue t a -> STM [(t, a)]
- type Picker a = [(a, STM ())] -> STM (a, STM ())
- popQueue :: forall a t. Ord t => Picker a -> Queue t a -> IO (Maybe a)
- queueRunner :: Ord t => Picker a -> (a -> IO ()) -> Queue t a -> IO ()
- newQueueWithRunners :: EnumBounded t => Int -> Map t Prio -> Picker a -> (a -> IO ()) -> IO (Queue t a, [IO ()])
Documentation
type EnumBounded t = (Ord t, Enum t, Bounded t) #
singletonQ :: a -> Q a #
normalizeQ :: Q a -> Q a #
A queue with different kinds of values, described by t
, where each
kind can have a higher or lower priority than other kinds, as described
by the queuePrios
field.
defaultPrios :: EnumBounded t => Map t Prio #
Default priorities for the enumeration of job types t
: everyone at 0.
newQueue :: EnumBounded t => Map t Prio -> IO (Queue t a) #
Create a new queue that'll apply the given priorities
addQueue :: Ord t => t -> a -> Queue t a -> STM () #
Add a new element to the queue, with the given kind.
debugDumpQueue :: (Enum t, Bounded t, Ord t) => Queue t a -> STM [(t, a)] #
Dump the contents of the queue, for debugging purposes.
popQueue :: forall a t. Ord t => Picker a -> Queue t a -> IO (Maybe a) #
Figure out the candidates for being popped from the various queues. We always look at highest priority queues first, and will pick between equal priority items of different queues (candidates, elements of the returned lists) by choosing the one that was queued first.
queueRunner :: Ord t => Picker a -> (a -> IO ()) -> Queue t a -> IO () #
A ready-to-use runner that pops the highest priority item off the queue and processes it using the given function.
:: EnumBounded t | |
=> Int | number of runners |
-> Map t Prio | priorities |
-> Picker a | how to pick between equal priority items |
-> (a -> IO ()) | what to do with each item |
-> IO (Queue t a, [IO ()]) |
Create a queue and n
runner actions for it, with the given priorities
for the runners to apply when picking a new item.