diff options
-rw-r--r-- | Run/Que.hs | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -78,10 +78,10 @@ routes = do -- ensure namespace exists app . modify <| upsertNamespace ns q <- app <| que ns qp - poll <- Scotty.param "poll" :: Scotty.ActionT Text App Text + poll <- Scotty.param "poll" !: (pure . const False) case poll of - "true" -> Scotty.stream $ streamQue q - _ -> do + True -> Scotty.stream $ streamQue q + _ -> do r <- liftIO <| takeQue q Scotty.text <| fromStrict <| Encoding.decodeUtf8 r @@ -95,6 +95,13 @@ routes = do liftIO <| pushQue (BSL.toStrict qdata) q return () +-- | recover from a scotty-thrown exception. +(!:) + :: Scotty.ActionT Text App a -- ^ action that might throw + -> (Text -> Scotty.ActionT Text App a) -- ^ a function providing a default response instead + -> Scotty.ActionT Text App a +(!:) = Scotty.rescue + -- | Forever write the data from 'Que' to 'Wai.StreamingBody'. streamQue :: Que -> Wai.StreamingBody streamQue q write _ = Go.mult q >>= loop |