protected async doBatchRequest()

in packages/dynamodb-batch-iterator/src/BatchGet.ts [45:92]


    protected async doBatchRequest() {
        const operationInput: BatchGetItemInput = {RequestItems: {}};
        let batchSize = 0;

        while (this.toSend.length > 0) {
            const [tableName, item] = this.toSend.shift() as [string, AttributeMap];
            if (operationInput.RequestItems[tableName] === undefined) {
                const {
                    projection,
                    consistentRead,
                    attributeNames,
                } = this.state[tableName];

                operationInput.RequestItems[tableName] = {
                    Keys: [],
                    ConsistentRead: consistentRead,
                    ProjectionExpression: projection,
                    ExpressionAttributeNames: attributeNames,
                };
            }
            operationInput.RequestItems[tableName].Keys.push(item);

            if (++batchSize === this.batchSize) {
                break;
            }
        }

        const {
            Responses = {},
            UnprocessedKeys = {},
        } = await this.client.batchGetItem(operationInput).promise();

        const unprocessedTables = new Set<string>();
        for (const table of Object.keys(UnprocessedKeys)) {
            unprocessedTables.add(table);
            this.handleThrottled(table, UnprocessedKeys[table].Keys);
        }

        this.movePendingToThrottled(unprocessedTables);

        for (const table of Object.keys(Responses)) {
            const tableData = this.state[table];
            tableData.backoffFactor = Math.max(0, tableData.backoffFactor - 1);
            for (const item of Responses[table]) {
                this.pending.push([table, item]);
            }
        }
    }