Module

Queue

Package
purescript-queue
Repository
athanclark/purescript-queue

Un-indexed queues with a set of handlers - this is useful for sending messages to a set of recipients, where removing them individually from the queue isn't necessary (but incremental additions are). This could be useful in interfaces where the list of handlers strictly increases, then gets wiped all at once if desired (i.e. a feed of social media posts).

#Queue Source

newtype Queue (rw :: Row SCOPE) a

Constructors

Instances

#new Source

new :: forall a. Effect (Queue (read :: READ, write :: WRITE) a)

#put Source

put :: forall a rw. Queue (write :: WRITE | rw) a -> a -> Effect Unit

Supply a single input to the queue.

#putMany Source

putMany :: forall a rw. Queue (write :: WRITE | rw) a -> NonEmptyArray a -> Effect Unit

Supply many inputs in batch to the queue.

#on Source

on :: forall a rw. Queue (read :: READ | rw) a -> Handler a -> Effect Unit

Add a handler to the unindexed queue.

#once Source

once :: forall a rw. Queue (read :: READ | rw) a -> Handler a -> Effect Unit

Treat this as the only handler, and on the next input, clear all handlers.

#draw Source

draw :: forall a rw. Queue (read :: READ | rw) a -> Aff a

Pull the next asynchronous value out of a queue. Doesn't affect existing handlers (they will all receive the value as well).

#read Source

read :: forall a rw. Queue rw a -> Effect (Array a)

Read all pending values (if any), without removing them from the queue.

#take Source

take :: forall a rw. Queue (write :: WRITE | rw) a -> Effect (Array a)

Take all pending values (if any) from the queue.

#del Source

del :: forall a rw. Queue (read :: READ | rw) a -> Effect Unit

Removes the registered callbacks, if any.

#drain Source

drain :: forall a rw. Queue (read :: READ | rw) a -> Effect Unit

Adds a listener that does nothing, and "drains" any pending messages.

Re-exports from Queue.Types

#WRITE Source

data WRITE :: SCOPE

#READ Source

data READ :: SCOPE

#Handler Source

type Handler a = a -> Effect Unit

#QueueScope Source

class QueueScope (q :: Row SCOPE -> Type -> Type) 

#SCOPE Source

data SCOPE :: Type