francescortiz / elm-queue / Queue

Queues for parallel processing or rate limiting. They are totally type agnostic, soy they serve general use case. You can enqueue any elm type, even Cmd or Msg.

Keyed queues

By providing a key you prevent duplicate entries in the queue. It also allows to remove specific entries.


type Queue a

Keyed queue. Keyed queues don't have duplicates. You have to dequeue items that have in started in order to free up space in the queue pool.

empty : Basics.Int -> Queue a

Created empty Queue. You have to specify the size of pool (or parallelization count).

enqueueAndStart : String -> a -> Queue a -> ( Queue a, List a )

Add entry to the queue and start processing it (get first elements to start processing them).

start : Queue a -> ( Queue a, List a )

Start processing the queue (get first elements to start processing them). You need to call dequeue on complete items in order to free up pool space.

enqueue : String -> a -> Queue a -> Queue a

Add one element to the queue. You have to provide a key be able to track the item completion.

queue
    |> enqueue "get-user-photo" httpRequest
    |> start

enqueueMany : List ( String, a ) -> Queue a -> Queue a

Add many elements to the queue.

dequeue : String -> Queue a -> Queue a

Mark an element of the queue as complete. You have to provide the element key. This also frees up space in the pool.

queue
    |> dequeue itemKey
    |> start

Unkeyed queues

Simple lists of tasks, duplication allowed. Items cannot be removed.


type QueueUnkeyed a

Queue that does not care about when a task is finished.

emptyUnkeyed : Basics.Int -> QueueUnkeyed a

Create an empty unkeyed queue. You have to provide an integer value that states the number of items retrieved on each iteration.

init =
    ( { msgQueue = emptyUnkeyed 10
      }
    , Cmd.none
    )

startUnkeyed : QueueUnkeyed a -> ( QueueUnkeyed a, List a )

Start processing the queue (get first elements to start processing them). Started elements don't belong to the queue anymore.

startUnkeyed model.msgQueue

enqueueUnkeyed : a -> QueueUnkeyed a -> QueueUnkeyed a

Enqueue an item to an unkeyed queue. It allows to enqueue repeated elements.

enqueueUnkeyed (ItemMsg item) model.msgQueue

enqueueManyUnkeyed : List a -> QueueUnkeyed a -> QueueUnkeyed a

Enqueue a list of items to an unkeyed queue queue.

enqueueManyUnkeyed [ ItemMsg item1, ItemOtherMsg item1, ItemMsg item2 ] model.msgQueue