Created
July 20, 2018 04:37
-
-
Save sdawood/5eb7db9734a20f0d52dfde26dd103c31 to your computer and use it in GitHub Desktop.
Consuming the Async Generator with Throttling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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