last day (16 days later) » 

11:11 PM
0
Q: Amazon Alexa Skill Callback not being called

MikeI have an Alexa skill that takes the device's address and uses that information to find a nearby facility. I have taken a look at the solution here as proposed by @jfriend00. My callbacks are structured the same way. I still don't understand why my callbacks aren't returning before the rest of t...

 
Try moving it immediately after callback(null, response) when the promise Axios promise is resolved
Although theoretically it should fire as is, but in the wrong order due to how async/promises work
 
@djfdev, I just made an edit to the code, though not what you were suggesting. Am I on the right track?
 
I think you're misunderstanding how async works. Take a look at Felix King's answer in the link you provided. TLDR async functions (like Axios request, and your getJSON wrapper) return immediately, so it looks the new callback you added will run out of order.
 
I see what you're saying. Based on the logs, the code is returning out of order. What am I misunderstanding about async?
@djfdev, apologies, I have made a bunch of new edits
 
11:37 PM
Hey there Mike, I think the best way to understand this is to look at a simplified version of your code
```
So to start, here is a stripped down version of your getJSON function
I've edited the log messages to reflect what order they will actually occur in
And here is a stripped down version of getKaiserBuildingHelper pastebin.com/mGbj52dR
So basically what is happening is that Axios.get is an asynchronous function, meaning that it will return immediately, and your code will continue to run (that's why the messages get logged in the order I've described).
Then at a later time (i.e. when the HTTP request is complete), the function passed to then or catch will fire. This is known as a callback function.
So what this means is that the getJSON function actually returns before you have any response data. So when the callback function passed to getKaiserBuildingHelper is fired, the value of facilityOutput is still the initial value
Putting this all together, you can fix the problem by moving the callback inside of the getJSON callback pastebin.com/Hn0q8iGt
 

  last day (16 days later) »