diff options
author | Ben Sima <ben@bsima.me> | 2020-03-30 09:12:15 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-03-30 09:12:15 -0700 |
commit | 9663e948dfce5a080bd35488e5ee339958ecf0e8 (patch) | |
tree | a4cd4da00081acca37101acd9cc48bbda415f792 /Run | |
parent | a3fa7db77828374b9de2c57adad2c26a667234bf (diff) |
Rescue lack of poll param
Diffstat (limited to 'Run')
-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 |