Session.save() Asynchroneous ?

Former Member
Former Member
Hello,

I'm new to garmin app development so I'm looking at the Namaste App from github as an example.

It seems that developer triggers the session.save() through the model from the controller and then push a progress bar view for 3000 ms before doing some System.exit().

That leads me to think that Session.save is not synchroneous. Am I Right?

If I am, is there a better way to handle save() ? If the activity is very long it may be possible that 3000 ms is not enough to save.

Since Session.save() returns a boolean, is possible to do something like this ? :

while(!session.save()){

}

thanks in advance.

Sorry if you read this twice, but I did post in the wrong forum.
  • The place to ask is really in in the CIQ Developer Forum. This one is for non-CIQ things.

    That said, I'm not familiar with the github app you mention, but take a look at the RecordSample in the SDK. In my own apps, I simply do a session.save() and it's worked fine for a long time. I think the return will be more to indicate that it couldn't be saved (no space left) than that the operation is still in progress. See the API doc - the return is is the session was saved or not. You'll notice in the RecordSample the return isn't even checked.

    CIQ is single threaded, and in general, you really don't want to do anything like spin while waiting for something to change, as you'll trigger the watchdog timer.
  • Former Member
    Former Member
    Sorry for wrong posting I'll repost in the correct forum.

    The app I'm talking about is there https://github.com/garmin/connectiq-apps/tree/master/apps/namaste

    Thank you for your answer, it make sens to me. But I noticed that my watch is doing such a spin while waiting when built-in apps are waiting for GPS and when it is saving my activities...

  • With "spin" I was meaning a "spin" in the code (sometimes called a "spin lock", where you wait for another thread/process to do something), like
    while(!session.save()){

    }

    And not the visual on the screen.

    For things like GPS, every second the GPS info changes, but the app doesn't just loop waiting for it to change, and in fact, you can start recording when there hasn't been a GPS fix.
  • What I would do is push a view and start a timer. The view in this case would be a ProgressBar.

    function saveRecording() {
    if (feSession != null) {
    if (feSessionTimer == null) {
    feSessionTimer = new Timer.Timer();
    }
    var pb = new Ui.ProgressBar("Saving", null);
    Ui.pushView(pb, null, Ui.SLIDE_DOWN);
    feSessionTimer.start(method(:timerRecording), 1000, true);
    if (feSession.isRecording()) {
    feSession.stop();
    }
    feSessionRecorded = feSession.save();
    feSession = null;
    }
    }

    function timerRecording() {
    if (feSessionRecorded != null) {
    feSessionTimer.stop();
    feSessionRecorded = null;
    Ui.popView(Ui.SLIDE_UP);
    }
    }



    The timer code would check for the feSessionRecorded to be non-null and then you could determine what to do with the result. You would also pop the ProgressBar view at that point as well. I am not sure that it is safe or advisable to loop on the session.save() function. Repeated calls are probably not how it was intended and your also creating a block on the while as it waits.