Module

Threading.Channel

Package
purescript-threading
Repository
cakekindel/purescript-threading

#Channel Source

data Channel a

A multi-producer multi-consumer channel for communication between threads.

Senders will broadcast messages to all living receivers, doing nothing if there are no receivers.

Receivers can wait for messages to be sent. Messages that are sent while the receiver is not waiting will be buffered, and recvd in the order they were sent.

#Sender Source

data Sender a

#Receiver Source

data Receiver a

#recv Source

recv :: forall a. Receiver a -> Aff a

Block until a message is sent, and pop it from the queue.

If a message has been sent since the last call to recv, then it will be immediately popped & returned.

#tryRecv Source

tryRecv :: forall a. Receiver a -> Aff (Maybe a)

Read a queued message and pop it from the queue.

If no queued messages have been sent, returns Nothing.

#send Source

send :: forall a. Sender a -> a -> Aff Unit

Send a message to all living receivers

#peek Source

peek :: forall a. Receiver a -> Aff a

Block until a message is sent, and read it without removing it from the queue.

If a message has been sent since the last call to recv, then it will be immediately returned.

#tryPeek Source

tryPeek :: forall a. Receiver a -> Aff (Maybe a)

Read a queued message without altering the queue.

If no queued messages have been sent, returns Nothing.

#channel Source

channel :: forall a. Effect (Channel a)

Create a new channel

#sender Source

sender :: forall a. Channel a -> Effect (Sender a)

Create a new message sender

#receiver Source

receiver :: forall a. Channel a -> Aff (Receiver a)

Create a new message receiver