Cannot get a return value from an async query to another async query

Encountered this one today which has me puzzled.

I have a js query using the async pattern:

(async () => {
  const data1 = await jsTranslateRouteToLines.trigger()
  const data2 = await qryUpdateRouteLines.trigger({additionalScope: {index: selFilterLeg.value, lines: data1}})
})();

jsTranslateRouteToLines is also an async query that returns an object.

However, data1 is undefined. :confused:

jsTranslateRouteToLines doesn't actually need to use the async pattern (I just default to that most of the time) so when I make it a plain js query, all is good in the world.

This is probably the result of some stuff under the hood of JS so probably over my head. But would like to understand it better. Or maybe I am just doing something wrong.

What does the following return? [quote="bradlymathews, post:1, topic:10825"]
jsTranslateRouteToLines.trigger()
[/quote]

I would make sure your async boilerplate includes a return:

return (async () => {
  ...
})();

Otherwise the return value of your query will be undefined!

Ding, ding, ding. We have a winner!

That makes total sense in retrospect.

2 Likes