Skip to content

Instantly share code, notes, and snippets.

@sdawood
Created July 20, 2018 04:37
Show Gist options
  • Select an option

  • Save sdawood/5eb7db9734a20f0d52dfde26dd103c31 to your computer and use it in GitHub Desktop.

Select an option

Save sdawood/5eb7db9734a20f0d52dfde26dd103c31 to your computer and use it in GitHub Desktop.
Consuming the Async Generator with Throttling
const {RateLimiter} = require('limiter');
async function main(rate, interval) {
const rateLimiter = new RateLimiter(rate, interval);
for await (const iter of queryBatches('ExampleTable', {keyConditionExpressoin: {...}, expressionAttributeValues: {...}})) {
const {ConsumedCapacity} = iter.metadata();
for (const value of iter) {
// You can use functional-pipelines to reduce or transduce the iterator as needed
console.log(value);
}
// Throttling
await rateLimiter.getTokens(ConsumedCapacity);
}
}
main(10, 'second')
.then(result => console.log(result)
.catch(error => console.error(error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment