Commit eb130c71 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Correctly terminate results function

This commit fixes a bug in the 'results' function. This function
was not using the 'Ax.exhausted' function which checks if we are
done fetching results from Arxiv. As a result the generated 'Conduit'
would get stuck demanding results, resulting in the caller never
making progress.
parent 2d7e5753
......@@ -93,9 +93,9 @@ searchAxv' q =
in do rsp <- HT.httpBS =<< liftIO (parseRequest s)
case getResponseStatus rsp of
(Status 200 _) -> case getSoup (getResponseBody rsp) of
[] -> pure (0, C.yieldMany [])
soups@(s:_) -> pure (Ax.totalResults soups, results q soups)
st -> error $ "Error:" ++ show st
[] -> pure (0, C.yieldMany [])
soups -> pure (Ax.totalResults soups, results q soups)
st -> error $ "Error:" ++ show st
searchAxv :: (Monad m, C.MonadIO m) => Ax.Query -> C.ConduitT () Result m ()
searchAxv q =
......@@ -133,8 +133,10 @@ toSoup = C.awaitForever (C.yield . parseTags . B.unpack)
results :: (Monad m, C.MonadIO m) =>
Ax.Query -> [Soup] -> C.ConduitT () Result m ()
results q sp = do
Ax.forEachEntryM sp (C.yield . mkResult)
searchAxv (Ax.nextPage q)
if Ax.exhausted sp
then pure ()
else do Ax.forEachEntryM sp (C.yield . mkResult)
searchAxv (Ax.nextPage q)
----------------------------------------------------------------------
-- Get data and format
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment