Skip to content

Commit

Permalink
remove dependency on pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
bflyblue committed Oct 18, 2023
1 parent 1f25591 commit a982473
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Update version bounds to support GHC 9.6 and servant 0.20
- Drop support for `jsForAPI` and the dependency on `servant-js`
- Remove dependency on pipes, breaking change for `eventSource` function

## 0.2.1.0 -- 2021-04-21

Expand Down
3 changes: 0 additions & 3 deletions servant-event-stream.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ library
, lens >=4.17 && <6
, pipes >=4.3.9 && <4.4
, servant-foreign >=0.15 && <0.17
, servant-pipes >=0.15 && <0.17
, servant-server >=0.15 && <0.21
, text >=1.2.3 && <2.1
, wai-extra >=3.0 && <3.2

-- , servant-js >=0.9.4 && <0.10

hs-source-dirs: src
default-language: Haskell2010
ghc-options: -Wall
Expand Down
18 changes: 3 additions & 15 deletions src/Servant/API/EventStream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

Expand All @@ -31,16 +32,9 @@ import Network.HTTP.Media ( (//)
import Network.Wai.EventSource ( ServerEvent(..) )
import Network.Wai.EventSource.EventStream
( eventToBuilder )
import qualified Pipes
import Pipes ( X
, (>->)
, await
, yield
)
import Servant
import Servant.Foreign
import Servant.Foreign.Internal ( _FunctionName )
import Servant.Pipes ( pipesToSourceIO )

newtype ServerSentEvents
= ServerSentEvents (StreamGet NoFraming EventStream EventSourceHdr)
Expand Down Expand Up @@ -86,11 +80,5 @@ type EventSourceHdr = Headers '[Header "X-Accel-Buffering" Text] EventSource
instance MimeRender EventStream ServerEvent where
mimeRender _ = maybe "" toLazyByteString . eventToBuilder

eventSource :: Pipes.Proxy X () () ServerEvent IO () -> EventSourceHdr
eventSource prod = addHeader "no" $ pipesToSourceIO (prod >-> yieldUntilClose)
where
yieldUntilClose = do
e <- await
case e of
CloseEvent -> return ()
_ -> yield e >> yieldUntilClose
eventSource :: EventSource -> EventSourceHdr
eventSource = addHeader @"X-Accel-Buffering" "no"

0 comments on commit a982473

Please sign in to comment.