gargantext-0.0.7.1.5.3: Search, map, share
Safe HaskellSafe-Inferred
LanguageHaskell2010

Gargantext.Utils.Jobs.Queue

Synopsis

Documentation

type EnumBounded t = (Ord t, Enum t, Bounded t) #

data Q a #

Constructors

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 #

A priority is just a number. The greater, the earlier the job will get picked.

applyPrios :: Ord t => [(t, Prio)] -> Map t Prio -> Map t Prio #

data Queue t 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.

Constructors

Queue 

Fields

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.

deleteQueue :: (Eq a, Ord t) => t -> a -> Queue t a -> STM () #

debugDumpQueue :: (Enum t, Bounded t, Ord t) => Queue t a -> STM [(t, a)] #

Dump the contents of the queue, for debugging purposes.

type Picker a = [(a, STM ())] -> STM (a, STM ()) #

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.

newQueueWithRunners #

Arguments

:: 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.