Skip to content

Commit 0784b2b

Browse files
authored
Merge pull request #55 from paluh/master
Chunked `writeString` version working under aff-4.0.0 + related test cases
2 parents abba73f + f0c52d1 commit 0784b2b

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/Hyper/Node/Server.purs

+4-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Control.Monad.Aff.AVar (AVAR, makeEmptyVar, makeVar, putVar, takeVar)
1717
import Control.Monad.Aff.Class (class MonadAff, liftAff)
1818
import Control.Monad.Eff (Eff)
1919
import Control.Monad.Eff.Class (class MonadEff, liftEff)
20-
import Control.Monad.Eff.Exception (EXCEPTION, catchException, error)
20+
import Control.Monad.Eff.Exception (EXCEPTION, catchException)
2121
import Control.Monad.Error.Class (throwError)
2222
import Data.Either (Either(..), either)
2323
import Data.HTTP.Method as Method
@@ -61,14 +61,9 @@ newtype NodeResponse m e
6161
= NodeResponse (Writable () e -> m Unit)
6262

6363
writeString :: forall m e. MonadAff e m => Encoding -> String -> NodeResponse m e
64-
writeString enc str = NodeResponse $ \w -> liftAff (makeAff (writeAsAff w))
65-
where
66-
writeAsAff w k = do
67-
Stream.writeString w enc str (k (pure unit)) >>=
68-
if _
69-
then k (pure unit)
70-
else k (throwError (error "Failed to write string to response"))
71-
pure nonCanceler
64+
writeString enc str = NodeResponse $ \w ->
65+
liftAff (makeAff (\k -> Stream.writeString w enc str (k (pure unit))
66+
*> pure nonCanceler))
7267

7368
write :: forall m e. MonadAff e m => Buffer -> NodeResponse m e
7469
write buffer = NodeResponse $ \w ->

0 commit comments

Comments
 (0)