Question: how to paginate with token? (or recursively call async function and pass through parameters)
See original GitHub issueAWS API calls typically respond with a pagination token. When present, another call to the same API should be made with that token, until a token is no longer supplied. This is typically done using recursion.
I would like to use async
(or another library) to simplify this approach. I had imagined the following psuedo code:
await paginate(async (lastToken, recurse, page) => {
const { certificates, token } = await listCertificates({nextToken: lastToken})
handleCertificates(certificates)
token && recurse(token)
})
This illustrates how something as complicated as token based pagination could be accomplished with a few lines of code. I’ve looked into async and saw some relevant functions (e.g. until
), but have not found a way to recursively pass the output of one call to the next (i.e. pass in the token to the next call).
Is this possible with async
? Or is there a library that’s more suitable for this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
Practical Asynchronous Recursion in JavaScript - Medium
The function for listing a bucket 'listObjectsV2' is a paginated listing, so after each call the caller can check to see if another...
Read more >Async/Await for recursive API Calls - javascript - Stack Overflow
All async functions return a promise, always. So both getSelectAllIds() and someFunction() will always return a promise.
Read more >Asynchronous Recursion with Callbacks, Promises and Async.
The first approach we'll look at is a little old-fashioned, using callback functions. The first step is to change the getSentenceFragment ...
Read more >Pagination or while loop using recursion in Mule 4 - Mulesy.com
This Tutorial talks about how to make use of recursion in Mule 4 to solve pagination and while loop scenarios.
Read more >octokit/rest.js
All endpoint methods are asynchronous, in order to use await in the code ... To stop paginating early, you can call the done()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
doWhilst
is good for this kind of thing.Although, with
async
/await
, it’s easier to use a plaindo
/while
:@aearly I like how async/await makes something like do/while so simple to read again; thanks!