Closed bryanyuchen closed 7 years ago
I had a very similar issue just a few days ago. The problem is that when you emit, the SDK calls context.succeed()
which ends the Lambda execution, ignoring whatever is left in the Node event loop. To solve this, you need to make your emit
clause a callback of your updating code - i.e. make it so it only emit
s after it's finished updating the IoT shadows.
I have no experience with IoT shadows, but let me know if you need any further help. (Interestingly enough, your code should work when https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/pull/59 is merged so it calls callback()
not context.succeed()
, but that hasn't happened yet.)
Hi Tom,
Thank you so much for your helpful comments! I understand the situation much better now and fixed the issue by passing a callback to this.emit:
updateShadow( () => { this.emit(':tell', speechOutput); } ); //where updateShadow only takes 1 argument
No worries, and that's an ideal fix! Your original code really should work, and will work as soon as they get round to properly updating that part of the SDK.
In case anyone else is looking at this issue and wondering whether this is why their async code isn't working, I'll try to leave a comment when they've updated it. Once it's updated you won't need to put the emit in a callback anymore.
It seems that I'm not able to update my AWS IoT Shadows while using this sdk.
Regarding the case with handlers, I've found that the following is valid code, but fails to update the shadow
var handlers = {
};
Not exactly sure why this is the case, but I found that when I comment out the this.emit line, the function is actually able to update the shadow, but then there is no alexa response. Any help would be appreciated. Thanks!