Module

Queue

Un-indexed queues with a set of handlers - this is useful for broadcasting 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

newtype Queue (rw :: Row SCOPE) a

Either a non empty set of handlers, or a possibly empty set of pending values.

Constructors

Instances

#new

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

Re-exports from Queue.Types

#WRITE

data WRITE :: SCOPE

#SCOPE

data SCOPE

#READ

data READ :: SCOPE

#Handler

type Handler a = a -> Effect Unit

#Queue

class Queue (queue :: Row SCOPE -> Type -> Type)  where

Represents an un-indexed queue - such that identifying handlers is not supported.

Members

  • putMany :: forall a rw t. Traversable t => queue (write :: WRITE | rw) a -> t a -> Effect Unit

    Pushes multiple values on the stack of pending values, or traverses through the handler(s).

  • popMany :: forall a rw. queue (write :: WRITE | rw) a -> Int -> Effect (Array a)

    Pops as many values as indicated off the stack of pending values, if any, in the reverse order they were added - i.e. youngest first.

  • takeMany :: forall a rw. queue (write :: WRITE | rw) a -> Int -> Effect (Array a)

    Pops as many values as indicated off the stack of pending values, if any, in the same order they were added - i.e. oldest first.

  • takeAll :: forall a rw. queue (write :: WRITE | rw) a -> Effect (Array a)

    Equivalent to length q >>= takeMany q, but without the overhead.

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

    Assign a handler to capture queue events.

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

    Removes a handler after first run.

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

    Removes all handlers from the queue, without affecting the cache.

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

    Observes the values in the queue without deleting them.

  • length :: forall a rw. queue rw a -> Effect Int

    Length of the cache.

#QueueExtra

class QueueExtra (queue :: Row SCOPE -> Type -> Type) 

#QueueScope

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

Members

#take

take :: forall a rw queue. Queue queue => queue (write :: WRITE | rw) a -> Effect (Maybe a)

Take the first added event.

#put

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

Put only one event.

#pop

pop :: forall a rw queue. Queue queue => queue (write :: WRITE | rw) a -> Effect (Maybe a)

Pop the latest added event.

#draw

draw :: forall rw a queue. Queue queue => 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). If this action is canceled, all handlers will be removed from the queue, because this interface is un-indexed.

#drain

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

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

Modules