Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 异步lambda函数中被忽略的函数_Node.js_Asynchronous_Lambda_Amazon Dynamodb_Async.js - Fatal编程技术网

Node.js 异步lambda函数中被忽略的函数

Node.js 异步lambda函数中被忽略的函数,node.js,asynchronous,lambda,amazon-dynamodb,async.js,Node.js,Asynchronous,Lambda,Amazon Dynamodb,Async.js,我正在创建一个系统,使用API检查玩家数据,然后更新到我的DynamoDB,但似乎中途停止了?作为让我们扫描我们的球员并更新统计数据从未显示在我的日志中 exports.handler = async (event, context) => { var documentClient = new AWS.DynamoDB.DocumentClient(); var params = { TableName: 'games', FilterE

我正在创建一个系统,使用API检查玩家数据,然后更新到我的DynamoDB,但似乎中途停止了?作为<代码>让我们扫描我们的球员并更新统计数据从未显示在我的日志中

exports.handler = async (event, context) => {

    var documentClient = new AWS.DynamoDB.DocumentClient();

    var params = {
        TableName: 'games',
        FilterExpression:'updated_at = :updated_at',
        ExpressionAttributeValues: {
            ":updated_at": 0,
        }
    };
    var rows = await documentClient.scan(params).promise();

    let gameAPI = new GameAPI();

    await gameAPI.login().then(function() {

        console.log("We have logged into our game!");

        rows.Items.forEach(function(match) {

            console.log("Let's look at our match! " + match.id);

            var player_params = {
                TableName: 'players',
                FilterExpression:'match_id = :match_id',
                ExpressionAttributeValues: {
                    ":match_id": match.id,
                }
            };

            documentClient.scan(player_params).promise().then(row => {

                console.log("Let's scan our players & update stats!");

            });

        });

    });

};

我假设这与我的
async
wait
函数有关?有人能给我指一下正确的方向吗。

你把
等待
然后
混在一起了

试试这个:

exports.handler = async (event, context) => {

    var documentClient = new AWS.DynamoDB.DocumentClient();

    var params = {
        TableName: 'games',
        FilterExpression:'updated_at = :updated_at',
        ExpressionAttributeValues: {
            ":updated_at": 0,
        }
    };
    var rows = await documentClient.scan(params).promise();

    let gameAPI = new GameAPI();

    await gameAPI.login();

    console.log("We have logged into our game!");

    for (let match of rows.Items) {

        console.log("Let's look at our match! " + match.id);

        var player_params = {
            TableName: 'players',
            FilterExpression:'match_id = :match_id',
            ExpressionAttributeValues: {
                ":match_id": match.id,
            }
        };

        let row = await documentClient.scan(player_params).promise();
        console.log("Let's scan our players & update stats!");
    }
};
then
的工作方式是基于回调的:

documentClient.scan(params).promise().then((rows) => {
    // do something with the rows
});
While
wait
/
async
的工作原理是消除回调,使您的代码看起来同步且更可读

const rows = await documentClient.scan(params).promise();
// do something with the rows

你似乎在混合使用
wait
。那么
,有什么原因吗?@OllysCoding没有,我只是对异步的东西不太在行;所以这就是混搭lol