I've got a function which produces an infinite list of monadic actions (HTTP calls in my case), something like this:
getStream = foldMap makeHttpCall [1..]
where
makeHttpCall bookId = ...
I'd like to be able to use this function like this:
S.take 10 $ (asyncly getStream)
Two things I'm trying to achieve:
- I don't want to pass the
10
to thegetStream
function - I want the 10 HTTP calls to be made at the same time
The code above makes more than 10 HTTP calls, and whatever comes back first is passed in the stream. I've explored other combinators like wAsyncly
and parallely
but the behaviour stays the same.
Is there a way to achieve this in Streamly?
Code samples above use the following imports:
import Streamly
import qualified Streamly.Prelude as S