Implement async iterator to KeyValueStore?
Since you can use KeyValueStore.forEachKey, and now Apify containers uses Node 10 as default, it might be interesting to be able to use it on a for-await-of loop:
const myAsyncFn = async () => {
const kvStore = await Apify.openKeyValueStore();
for await (const [key, value] of kvStore.entries()) {
// and other Object methods, like values(), keys(), etc,
// or even the iterate the kvStore var itself using [Symbol.asyncIterator]() { }
// can await here as well
}
}
the good thing about this is that it allows to be executed in the async function scope, instead of having to pass in another async closure. I was implementing this myself, but then I thought it would be a great addition to the library (might as well add it to Dataset, right now it's all or nothing). another plus is that you can break the loop without having to throw
You're right. We've had this in mind for quite some time, but since its mostly a convenience feature, we were postponing it. Thanks for creating the issue. I promise we'll get to it at some point.