Is there a way to wait for a asynchronous callback and continue with execution after callback is received?

Hi All,

I'm new to Garmin wearable development, so please forgive me possibly wierd question, but I have not found an answer anywhere - Though I was searching a lot.

Thanks for any reply in advance. (Read long story short in bold)

The issue:

I´m creating an app that needs to fetch some json data using makeWebRequest on background - specifically in onTemporalEvent.

Everything is basically working as expected - EXCEPT: 

In my onTemporalEvent Im making a web request which is processed successfully and returns valid data in its callback.

Under certain conditions I want to notify user that there is something new based on the fetched data so I want to call requestApplicationWake from makeWebRequest callback.

In a point of time the data arives and are processedonTemporalEvent is already out of scope (or callback function is not running in a scope of background at all) - therefore requestApplicationWake does not take effect.

if I call requestApplicationWake from onTemporalEvent directly - I will get a prompt. however calls of requestApplicationWake beyond onTemporalEvent lifetime (understand from webRequest callback) executes with NOP.

Is there a way to wait for a web request callback in onTemporalEvent or ensure requestApplicationWake is called within background context anyhow so that requestApplicationWake is sent within onTemporalEvent after web request data are received?

Any possible workaround?

Thanks,

Martin

*(I know the background task lifetime is 30s maximum and that only onTemporalEvent is guaranteed to execute, but not its child processes possibly)

  • As noted above - I tested this on actual Fénix 5 plus and no prompt or anything was given. Needless to say - Im not sure if or how to use gdb in this scenario - nevertheless functionally same as simulator. As Im comming from different background please forgive my confusion - its my first project - but behavior I observe is quite expected for me .. you make a async  request and you have a reply some time in future - nobody waits for you unless you specifically care - so having implicitly blocking async calls is something unusual for me and i mostly beleive, what i see. Unfortunatelly here I see what I’d normally expect: i make async call. I got async reply. Unless I take care that I want to wait for a reply and continue synchronously - It just pops within timeout or expires. Looking at monkeyc - and api docs - it seems that this could block withiut any guarantee

    back to toppic 

    i know if I bypass the async call - prompt is given - i.e. If a call wake+exit is made from onTemporal event directly - Im propted with msg.

    do you know, if there is any refference project, I could use to check the functionality / setup?

    many thanks for your help.

    appreciate..

  • Could you give a short description of what it is you want to do here?  Like I said what you're trying to do should work, but there may be a better way to do what you want to do