Have to add delays after query.run() before reading query.data in JSObjects

I’m trying to use queries within JSObjects in this fashion:

func: async () => 
{
  await query.run();
  // Have to do this, otherwise, next line will fail intermittently. 
  await new Promise(r => setTimeout(r, 500));
  var res = query.data["result"];
  console.log(res);
}

I thought based on the docs that awaiting query.run() should wait until query settles and data is available in query.data property. However, it seems it is not the case and I have to add delays to make sure accessing query.data doesn’t fail.

Am I missing something?

Hey @Mike99!

You can shorten the first four lines to one like this:

const res = await query.run()

This will always grab the response from the query. I use Query.data to bind query data to widgets, but in raw JS I always use the above syntax to get the response.