Node.js 异步lambda函数中被忽略的函数
我正在创建一个系统,使用API检查玩家数据,然后更新到我的DynamoDB,但似乎中途停止了?作为<代码>让我们扫描我们的球员并更新统计数据代码>从未显示在我的日志中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
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
});
Whilewait
/async
的工作原理是消除回调,使您的代码看起来同步且更可读
const rows = await documentClient.scan(params).promise();
// do something with the rows
你似乎在混合使用
wait
和。那么
,有什么原因吗?@OllysCoding没有,我只是对异步的东西不太在行;所以这就是混搭lol