0

I hesitated to bring this question to StackOverflow because I'm not certain it's the type of thing the forum wishes to see. If not, just tell me so; I apologize in advance.

I have working code which I wanted to "elegantize" by moving some of the main inline code to a function and replacing it inline with a function call. But there's something wrong with the logic when I do. I've been messing with it for half a day and can't see it, though I'm sure it's something simple and stupid.

I've used screenshots instead of entering the code because the console log refers to line numbers which the screenshots show.

From the console log, it appears that, in the function, execution drops straight through to checkpoint 2 (line 48 of the modified code) leaving the dynamodb.scan statement (line 42) unexecuted and the var data (at line 52) undefined. It also appears that the function gets executed a second time because, after the logged 'undefined' error, execution somehow gets to checkpoint 0.5 (line 43).

This is a screenshot of the working code with the part I wanted to make a function outlined.

This is a screenshot of the modified code.

This is a screenshot of the console log.

Again, I apologize if this is an inappropriate question, but if a forum member can help, it would let a novice know what he's done wrong and would be greatly appreciated.

alxfyv
  • 389
  • 1
  • 6
  • 18
  • 1
    `getDynamoDBTableData` is asynchronous, you can cannot "return" anything from it nor can you assign its return value. As long as your target platform doesn't support async/await your best bet is to promisify this function and put the rest of the logic in a promise chain. The duplicate question has all details about the topic. – georg Mar 14 '17 at 23:09
  • @georg Thanks so much. I've a lot yet to understand and reading to do. – alxfyv Mar 14 '17 at 23:17

0 Answers0