Fork me on GitHub
Jakub Holý (HolyJak)08:11:42

Thanks a lot to everybody who advised me on improving my function to fetch blog posts from a paginated API. I have applied your idea to use a dedicated stop-signal instead of just closing the output dst channel, which simplified the code, and @hiredman’s excellent idea to factor out the looping by creating an async version of core iterate (it took me a while to understand it fully and I ended up writing a less flexible but easier for me to understand version of it). Here is the original async-fetch-all-posts combining async/thread, try, loop, let, when & if and here is the refactored and renamed fetch-posts-async! (Here I start the process producing pages of data and here is the factored-out async-iterate If you have any comments, they would be of course most welcome. It is more code now but simpler (not easier :)), I think.