1
AWS Lambdaを使用して私の最初のAlexaスキルを開発しています。 問題は、すべての同期関数が実行される前にラムダ関数が完了することです。 私がfuctionをテストすると、時々出力が得られるだけです 'Aは完了です(hereから)から の例を使用しています。 ' B()、C()、D()を実行せずに関数を返します。IntentHandlerによって呼び出される関数が完了する前に、AWS Lambda関数が返されます。
私はGetUpdateIntentからA()を呼び出しています。コールバックが完了するように、コールバック でcontext.done()を使用することを提案している投稿はほとんど読んでいません。私はこれを達成する方法に従うことができません。 ラムダ関数が完了する前に、すべてのコールバックと非同期呼び出しが完了するのが好きです。
var A = function() {
return new Promise(function(resolve, reject) {
var result = 'A is done'
console.log(result)
resolve(result);
})
}
var B = function() {
return new Promise(function(resolve, reject) {
var result = 'B is done'
setTimeout(function() {
console.log(result)
resolve(result);
}, 2000)
global_context.done();
})
}
var C = function() {
return new Promise(function(resolve, reject) {
var result = 'C is done'
console.log(result)
resolve(result);
})
}
var D = function() {
return new Promise(function(resolve, reject) {
var result = 'D is done'
console.log(result)
resolve(result);
})
}
A()
.then(function(result) {
return B();
})
.then(C)
.then(D)
.then(console.log("All done"));
Example.prototype.intentHandlers = {
GetUpdateIntent: function(intent, session, response){
A();
},
};
exports.handler = function(event, context) {
var skill = new Example();
skill.execute(event, context);
};