Module

Concurrent.Channel

Package
purescript-channel
Repository
ConnorDillon/purescript-channel

#Output Source

newtype Output a

An Output is a wrapper around a function that sends values to a Channel.

Constructors

Instances

#Input Source

newtype Input a

An Input is a wrapper around a function that receive values from a Channel.

Constructors

Instances

#Channel Source

type Channel o i = { close :: Aff Unit, input :: Input i, output :: Output o }

A Channel is an abstraction over a var, queue or stream backend and can be used as a communication channel between async threads.

#recv Source

recv :: forall a. Input a -> Aff (Maybe a)

Receives a value from an Input. If the Input is closed, the result will be Nothing.

#send Source

send :: forall a. Output a -> a -> Aff Boolean

Sends a value to an Output. Will return false if the Output is closed and true if not.

#newChannel Source

newChannel :: forall a. Effect (Channel a a)

Creates a new Channel using an AVar backend.

#avarChannel Source

avarChannel :: forall a. AVar a -> Effect (Channel a a)

Creates a new Channel with a provided AVar as backend.

#inner Source

inner :: forall o i o' i'. Channel o i -> Channel o' i' -> Channel o' i

Creates a new Channel using the Input from the first provided Channel and the Output from the second. Closing the new Channel will also close the provided two Channels.

#connect Source

connect :: forall a. Input a -> Output a -> Effect Unit

Launches an async thread that sends all values from the Input to the Output in the background.

#recvList Source

recvList :: forall m. MonadAff m => Input ~> (ListT m)

Lazily drains an Input into a ListT. The list will end when the Input is closed.

#sendList Source

sendList :: forall m a. MonadAff m => Output a -> ListT m a -> m Boolean

Sends a ListT into an Output. Returns false if the Output was closed before the entire list was sent.

#sendTraversable Source

sendTraversable :: forall t a. Traversable t => Output a -> t a -> Aff Boolean

Sends a Traversable into an Output. Returns false if the Output was closed before the entire traversable was sent.