Knowing when eachPage is on the last page
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 768
- Forks
- 191
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/mapbox/mapbox-sdk-js/pull/272 added a little to the docs to illustrate the best current method for knowing whether your eachPage callback is on its last iteration.
There are a couple of other API options we could consider that might improve this use case:
-
eachPagecould call the callback withnull, instead of a response, after it has exhausted the page list. (This is what the aws-sdk-js does.) This would be a breaking change, because it means everyeachPageuser would need to anticipate anullvalue for the response argument.request.eachPage((error, response, next) => { if (error) { // Handle error ... } if (!response) { // Do something after pages are exhausted ... } // Handle the response ... next(); }); -
eachPagecould return a Promise that resolves when all the pages have been passed through the callback. This would not be a breaking change, because the current usage ofeachPagewould continue to work the same: it would just be a feature addition.request.eachPage((error, response, next) => { if (error) { // Handle error ... } // Handle the response ... next(); }).then(() => { // Do something after pages are exhausted ... }, /* This Promise would never reject. */);
I'm leaning towards the Promise, because it's not a breaking change and seems like the preferable API.
@andrewharvey @mapbox/frontend-platform do you agree, or can you anticipate any problems with eachPage returning a Promise?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current eachPage API and the documentation changes in pull request 272. Compare the proposed null-response and Promise options, then identify which behavior the maintainers want. Done requires an agreed API direction and corresponding implementation and documentation scope, but this issue does not yet provide that decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100