-
-
Save qrilka/61c06822fe91a2e41c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Handler.Events where | |
import Control.Concurrent.STM | |
import Data.Text as T | |
import Import | |
import Network.Wai | |
import Network.Wai.EventSource (ServerEvent (..), eventSourceAppIO) | |
getEventsR :: Handler () | |
getEventsR = do | |
$(logDebug) "EVENTS" | |
chan0 <- getEventsChan <$> getYesod | |
chan <- liftIO $ atomically $ dupTChan chan0 | |
req <- waiRequest | |
runInnerHandler <- handlerToIO | |
res <- lift $ (eventSourceAppIO (runInnerHandler $ readCh chan)) req | |
sendWaiResponse res | |
readCh :: TChan ServerEvent -> Handler ServerEvent | |
readCh chan = do | |
$(logDebug) "------READING CHANNEL------" | |
liftIO $ atomically $ readTChan chan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment