purescript-contrib / purescript-aff-coroutines Goto Github PK
View Code? Open in Web Editor NEWHelper functions for creating coroutines with the Aff monad
License: MIT License
Helper functions for creating coroutines with the Aff monad
License: MIT License
The documentation provides the following example:
produce \emit -> do
log "Working..."
emit (Left "progress")
log "Done!"
emit (Right "finished")
I expect this output:
Working...
progress
Done!
finished
But I see this:
Working...
Done!
which I think shows that the consumer does not receive any value.
The Aff example (with produceAff) does work as expected.
Below is the full code. I've used version 6.0.0 and Aff 4.1.1.
module Main where
import Control.Monad.Eff (Eff)
import Control.Coroutine (Consumer, Producer, consumer, runProcess, ($$))
import Control.Coroutine.Aff (produce)
import Control.Monad.Aff (Aff, runAff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Control.Monad.Eff.Exception (EXCEPTION)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Prelude
type EmitFunction a r eff = (Either a r -> Eff (avar :: AVAR | eff) Unit)
p :: forall eff. Producer String (Aff (console :: CONSOLE, avar :: AVAR | eff)) String
p = produce f
where
f :: EmitFunction String String (console :: CONSOLE | eff) -> Eff (avar :: AVAR, console :: CONSOLE | eff) Unit
f emit = do
log "Working..."
emit (Left "progress")
log "Done!!!"
emit (Right "finished")
c :: forall eff. Consumer String (Aff (console :: CONSOLE | eff)) String
c = consumer \s -> liftEff (log s) $> Nothing
main :: forall eff. Eff (console :: CONSOLE, avar :: AVAR, err :: EXCEPTION | eff) Unit
main = void $ runAff logShow $ runProcess (p $$ c)
{-
$ pulp run
* Building project in /Users/joopringelberg/Code/purescript-node-net
* Build successful.
Working...
Done!!!
-}
I think this is a regression either with aff-coroutines or just coroutines.
The code below should print "Hello world" but it won't print anything. If you add the second emit call, it will print it. It won't work with just a single emit (Right unit)
either.
module Coroutines where
import Prelude
import Control.Monad.Aff (Aff, launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Console (CONSOLE)
import Control.Monad.Aff.Console (log)
import Control.Coroutine (Producer, runProcess, consumer, ($$))
import Control.Coroutine.Aff (produce)
import Data.Either (Either(Left))
import Data.Maybe (Maybe(Nothing))
producer :: forall eff. Producer Unit (Aff (avar ∷ AVAR | eff)) Unit
producer = produce \emit → do
emit (Left unit)
--emit (Left unit)
main ∷ forall eff. Eff (avar ∷ AVAR, err ∷ EXCEPTION, console ∷ CONSOLE | eff) Unit
main = void $ launchAff $ runProcess (producer $$ (consumer \_ -> log "Hello world" *> pure Nothing))
Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have in their README a short summary of the library's purpose, installation instructions, a quick start with a minimal usage example, and links to the documentation and contributing guide.
This library currently doesn't have a completed quick start in the README.
Describe the solution you'd like
The library needs a quick start section after the installation instructions. argonaut-codecs is one example of a library with a quick start.
Additional context
See the Governance repository for more information about requirements in the Contributors organization.
Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have mostly complete module documentation, preferably uploaded to Pursuit.
This library currently doesn't have sufficient module documentation -- these functions and types have no documentation at all:
purescript-aff-coroutines/src/Control/Coroutine/Aff.purs
Lines 23 to 35 in de4764b
Describe the solution you'd like
We need to add documentation to these types and functions. Once updated, we should tag a release and upload new module documentation to Pursuit so that folks can use it.
Additional context
See the Governance repository for more information about requirements in the Contributors organization.
Pursuit gives access to version 5.0.0 and version 7.0.0. However, version 5 contains three small coding errors that have been repaired in 6 (6 can be obtained through Bower).
Regards, Joop
I'm listed as maintainer, but maybe I shouldn't be. I think this is used in Halogen, so maybe someone who uses Halogen would like to maintain this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.