question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
stevagecommented, Sep 14, 2018

Yeah, it turns out .all() is what I was really looking for, and that works fine.

9reactions
kasrakcommented, Aug 20, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found