eachPage Promisified behaviour
See original GitHub issue@kasrak Thanks for this work.
Could you also provide a snippet showing how the eachPage
of a Query
object behaves when promisifed?
Since the promise versions are used when the last callback is omitted, for the eachPage version that would be the done
method. (Although the callbackArgIndex
is specified, it still points at the last argument which is the done
callback).
Is this the correct promisified usage of the eachPage
function?
const data = [];
await table.select({}).eachPage((records, next) => {
data.push(...records);
next();
});
If so, it is still a bit weird to have to use a callback and implement the iterator/accumulator. where the promise happinness cannot be used to handle the async io taking place.
perhaps a better API would return a cursor with a promisified “next” method on it… (waving hands here)
const cursor = await table.select({}).eachPage();
while (cursor.hasMore) {
const moreRecords = await cursor.next();
...
}
Thanks Again!
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
nodejs - Help "promisifying" a file read with nested promises
@vitaly-t Have been looking around and I'm struggling to understand how to "promisify" the eachsheet function. Is there an example you can point ......
Read more >Class v1.EventarcClient (2.2.0) | Node.js client library
The client will no longer be usable and all future behavior is undefined. Returns ... The maximum number of channel connections to return...
Read more >x-ray-wrapper - npm
Pagination support: Paginate through websites, scraping each page. ... of xray method chaining, since the other methods are not promisified.
Read more >Untitled
In each page, the process examines each returned lock to determine its relative ... Checking on new Dynamodb console shows similar behavior.
Read more >Promisification - The Modern JavaScript Tutorial
The code may look a bit complex, but it's essentially the same that we wrote above, while promisifying loadScript function. A call to...
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
Yeah, it turns out
.all()
is what I was really looking for, and that works fine.Yep, your usage above is correct! It’s admittedly a bit strange, but we wanted the promisification to be non-breaking.
In the common case where you just want to fetch all pages, you can use the
table.select({}).all()
method which returns a promise that resolves once all pages are fetched: https://github.com/Airtable/airtable.js/blob/master/lib/query.js#L98