Skip to content

Commit f0c52d1

Browse files
committed
Ignore return value of Node.Stream.writeString
From Node.Stream.writeString docs: "Returns false if the stream wishes for the calling code to wait for the 'drain' event to be emitted before continuing to write additional data; otherwise true." So it seems that it is enough to just wait till writing has finished which is done by our Aff continuation. I'm not sure but situation can be a bit more complicated if we take Aff Fibers into account and consider other "concurrent" writes...
1 parent abba73f commit f0c52d1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/Hyper/Node/Server.purs

Lines changed: 4 additions & 9 deletions
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)