Skip to content

Commit c95ee8e

Browse files
authored
Merge pull request #14 from natefaubion/aff-updates
Aff updates
2 parents b5c4a65 + eb10617 commit c95ee8e

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"url": "git://github.com/purescript-contrib/purescript-aff-coroutines.git"
1515
},
1616
"dependencies": {
17-
"purescript-aff": "^3.0.0",
17+
"purescript-aff": "^4.0.0",
1818
"purescript-coroutines": "^4.0.0"
1919
}
2020
}

src/Control/Coroutine/Aff.purs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Prelude
1010

1111
import Control.Coroutine (Producer, producer)
1212
import Control.Monad.Aff (Aff, runAff, forkAff)
13-
import Control.Monad.Aff.AVar (AVAR, makeVar, takeVar, putVar)
13+
import Control.Monad.Aff.AVar (AVAR, makeEmptyVar, takeVar, putVar)
1414
import Control.Monad.Aff.Class (class MonadAff, liftAff)
1515
import Control.Monad.Eff (Eff)
1616
import Control.Monad.Eff.Class (liftEff)
@@ -39,7 +39,7 @@ produce
3939
. ((Either a r -> Eff (avar :: AVAR | eff) Unit) -> Eff (avar :: AVAR | eff) Unit)
4040
-> Producer a (Aff (avar :: AVAR | eff)) r
4141
produce recv = produceAff \send ->
42-
liftEff (recv (void <<< runAff (const (pure unit)) pure <<< send))
42+
liftEff (recv (void <<< runAff (const (pure unit)) <<< send))
4343

4444
-- | A version of `produce` that creates a `Producer` with an underlying
4545
-- | `MonadAff`, rather than `Aff` specifically.
@@ -57,14 +57,16 @@ produce' = hoistFreeT liftAff <<< produce
5757
-- |
5858
-- | ```purescript
5959
-- | produceAff \emit -> do
60-
-- | later' 1000 $ emit $ Left "progress"
61-
-- | later' 1000 $ emit $ Right "finished"
60+
-- | delay $ Milliseconds 1000
61+
-- | emit $ Left "progress"
62+
-- | delay $ Milliseconds 1000
63+
-- | emit $ Right "finished"
6264
-- | ```
6365
produceAff
6466
:: forall a r eff
6567
. ((Either a r -> Aff (avar :: AVAR | eff) Unit) -> Aff (avar :: AVAR | eff) Unit)
6668
-> Producer a (Aff (avar :: AVAR | eff)) r
6769
produceAff recv = do
68-
v <- lift makeVar
69-
_ <- lift (forkAff (recv (putVar v)))
70+
v <- lift makeEmptyVar
71+
_ <- lift (forkAff (recv (flip putVar v)))
7072
producer (takeVar v)

test/Main.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Control.Monad.Eff.Class (liftEff)
1111
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
1212
import Control.Monad.Eff.Exception (EXCEPTION)
1313

14-
import Data.Either (Either(..))
14+
import Data.Either (Either(..), either)
1515
import Data.Maybe (Maybe(..))
1616
import Data.Newtype (wrap)
1717

@@ -30,4 +30,4 @@ c :: forall eff. Consumer String (Aff (console :: CONSOLE | eff)) String
3030
c = consumer \s -> liftEff (log s) $> Nothing
3131

3232
main :: forall eff. Eff (console :: CONSOLE, avar :: AVAR, err :: EXCEPTION | eff) Unit
33-
main = void $ runAff logShow log $ runProcess (p $$ c)
33+
main = void $ runAff (either logShow log) $ runProcess (p $$ c)

0 commit comments

Comments
 (0)