Module

Concurrent.BoundedQueue

Package
purescript-concurrent-queues
Repository
purescript-contrib/purescript-concurrent-queues

A concurrent FIFO data structure with bounded capacity.

This datastructure is useful in various consumer/producer situations.

#new Source

new :: forall a. Int -> Aff (BoundedQueue a)

Creates a new BoundedQueue with the given capacity,

#write Source

write :: forall a. BoundedQueue a -> a -> Aff Unit

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

#read Source

read :: forall a. BoundedQueue a -> Aff a

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

#isEmpty Source

isEmpty :: forall a. BoundedQueue a -> Aff Boolean

Checks whether the given queue is empty. Never blocks.

#tryRead Source

tryRead :: forall a. BoundedQueue a -> Aff (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 a. BoundedQueue a -> a -> Aff 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.

Re-exports from Concurrent.BoundedQueue.Internal

#BoundedQueue Source

newtype BoundedQueue a