Module
Control.Coroutine.Aff
- Package
- purescript-aff-coroutines
- Repository
- purescript-contrib/purescript-aff-coroutines
This module defines functions for creating coroutines on top of the Aff
monad.
The Aff monad only supports actions which return a single value,
asynchronously, so this module provides a principled way to deal with
asynchronous streams of values, and asynchronous consumers of streamed
data.
#produce Source
produce :: forall a r. (Emitter Effect a r -> Effect Unit) -> Producer a Aff rCreate a Producer using an asynchronous callback.
The callback should provide zero or more values of type a, which will be
emitted by the Producer, terminated by an optional value of type r. No values
should be provided after a value of type r has been provided.
For example:
produce \emitter -> do
log "Working..."
emit emitter "progress"
log "Done!"
close emitter "finished"
#produceAff Source
produceAff :: forall a r. (Emitter Aff a r -> Aff Unit) -> Producer a Aff rA variant of produce where the setup and callback functions use the Aff
monad. This can be helpful in certain cases.
For example:
produceAff \emitter -> do
delay $ Milliseconds 1000
emit emitter "progress"
delay $ Milliseconds 1000
close emitter "finished"
- Modules
- Control.
Coroutine. Aff