async-by-page
When you need to operate on a list of things, but you can only get 1 page at a time.
This might already exist, but it's something I've had to do a few times recently so it's time to make a lib.
Usage
const byPage = require('async-by-page')
byPage(fetchNextPage, (item, next) => {
if (item.isSubscribedToNewsletter) { return next() }
sendEmail(item, next)
})
let page = 1
function fetchNextBatch (cb) {
getLeadsBatch(page, (err, res) => {
page += 1
return cb(err, res)
})
}
Can I use it? Is it stable?
Not really :) I'm going to be trying a few different things first, and adding a couple of extra features (eg. option for running in parallel VS series). But your feedback is still welcome. I'd also like to write an implementation with pull-streams because I think it would be a very useful comparison (and probs much cleaner too!).
License
MIT