Giter VIP home page Giter VIP logo

purescript-aff-coroutines's Introduction

Aff Coroutines

CI Release Pursuit Maintainer: garyb

Helper functions for creating coroutines with the Aff monad.

Installation

Install aff-coroutines with Spago:

spago install aff-coroutines

Quick start

The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the docs directory.

Documentation

aff-coroutines documentation is stored in a few places:

  1. Module documentation is published on Pursuit.
  2. Usage examples can be found in the test suite.

If you get stuck, there are several ways to get help:

Contributing

You can contribute to aff-coroutines in several ways:

  1. If you encounter a problem or have a question, please open an issue. We'll do our best to work with you to resolve or answer it.

  2. If you would like to contribute code, tests, or documentation, please read the contributor guide. It's a short, helpful introduction to contributing to this library, including development instructions.

  3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the PureScript Discourse! Writing libraries and learning resources are a great way to help this library succeed.

purescript-aff-coroutines's People

Contributors

garyb avatar hdgarrood avatar jordanmartinez avatar kl0tl avatar natefaubion avatar paf31 avatar pete-murphy avatar th-awake avatar thomashoneyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

purescript-aff-coroutines's Issues

First call to emit won't produce a value

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))

Library is missing some module documentation

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:

newtype Emitter m a r = Emitter (Step a r -> m Unit)
derive instance newtypeEmitter :: Newtype (Emitter m a r) _
data Step a b
= Emit a
| Finish b
emit :: forall m a r. Emitter m a r -> a -> m Unit
emit (Emitter f) = f <<< Emit
close :: forall m a r. Emitter m a r -> r -> m Unit
close (Emitter f) = f <<< Finish

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.

Maintainer?

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?

The example does not work as expected

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!!!
-}

Repository doesn't have a quick start section in the README

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.