Module

Concurrent.BoundedQueue

Package
purescript-concurrent-queues
Repository
slamdata/purescript-concurrent-queues

A concurrent FIFO data structure with bounded capacity.

This datastructure is useful in various consumer/producer situations.

#BoundedQueue Source

newtype BoundedQueue a

#new Source

new :: forall eff a. Int -> Aff (avar :: AVAR | eff) (BoundedQueue a)

Creates a new BoundedQueue with the given capacity,

#write Source

write :: forall eff a. BoundedQueue a -> a -> Aff (avar :: AVAR | eff) Unit

Writes an element to the given queue. Will block if the queue is full until someone reads from it.

#read Source

read :: forall eff a. BoundedQueue a -> Aff (avar :: AVAR | eff) a

Reads an element from the given queue, will block if the queue is empty, until someone writes to it.

#isEmpty Source

isEmpty :: forall eff a. BoundedQueue a -> Aff (avar :: AVAR | eff) Boolean

Checks whether the given queue is empty. Never blocks.

#tryRead Source

tryRead :: forall eff a. BoundedQueue a -> Aff (avar :: AVAR | eff) (Maybe a)

Attempts to read an element from the given queue. If the queue is empty, returns Nothing.

Careful! If other readers are blocked on the queue tryRead will also block.

#tryWrite Source

tryWrite :: forall eff a. BoundedQueue a -> a -> Aff (avar :: AVAR | eff) Boolean

Attempts to write an element into the given queue. If the queue is full, returns false otherwise true.

Careful! If other writers are blocked on the queue tryWrite will also block.