jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.31k stars 356 forks source link

Ability to iterate over cursor without await method #126

Closed mohit-sentieo closed 4 years ago

mohit-sentieo commented 4 years ago

I would like to iterate over a cursor. But unfortunately our large code base does not use async/await and this is causing a problem. I have decided to do something like this https://gist.github.com/mohit-sentieo/e161aa4fe5ac0eb1cbfb2579b62fb5f4

But this doesn't seem to be working. There should be a way to iterate over cursor without Promise recursion.

jakearchibald commented 4 years ago

Without async/await I would do this:

db.transaction(storeName).store.openCursor().then(function handleCursor(cursor) {
  console.log(cursor.key, cursor.value);
  return cursor.continue().then(handleCursor);
}).then(() => {
  console.log('done!');
});

Please reopen if that isn't the answer you're looking for!