Module

Concurrent.Channel

#Output

newtype Output a

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

Constructors

Instances

#Input

newtype Input a

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

Constructors

Instances

#Channel

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

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

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

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

Creates a new Channel using an AVar backend.

#avarChannel

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

Creates a new Channel with a provided AVar as backend.

#inner

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

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

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

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

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.

Modules