Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with async/await timing out

Hi,

 

I'm using async/await with a setTimeout() function and I'm getting that the following message on my versa

 

> App timeout triggered; app closing. See https://dev.fitbit.com/build/reference/device-api/appbit/#interface-appbit-

 

The code works on the Fitbit OS Simulator, though. I'm posting this to tell you guys about this discrepancy, but if you could share a possible solution for this problem, please let me know.

 

I'm using about 500ms for the timeout function. It's for an effect after the user clicks the selected object.  This is a sample of what the code is doing:

 

const speed = 500;

box.onclick = async function boxClick(e) {
    await presentItem(box);
}

async function presentItem(item) { 
    showItem(item);
    await wait(speed);
    hideItem(item);
    return item;
}

function showItem(item) {
    console.log('showing ' + item.id);
    item.style.opacity = 1;
    return item;
}

function hideItem(item) {
    console.log('hiding ' + item.id);
    item.style.opacity = 0.2;
    return item;
}

function wait(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

To be completely honest, when I only execute the function presentItem(item) the app doesn't crash, but when I execute the function within the onclick event it closes the app immediately and it throws that message.

Best Answer
0 Votes
10 REPLIES 10

Looks like you're just hitting the standard app timeout. Try disabling it.

 

https://dev.fitbit.com/blog/2018-10-05-announcing-fitbit-os-2.2/#app-timeout-api

Best Answer
0 Votes

Hi, Jon.

 

Thanks for the suggestion. That didn't help, though. I might have explained it incorrectly.

 

So, my problem occurs when I click on the DOM object. That error message doesn't even show anymore (with/without the code you suggested).

 

Your suggestion would fix if my app was inactive. That's not the case. I click on the object as soon as the app is initialized.

 

I also tried to decrease the timeout to 0 and it is still crashing... Not sure what to do, because I don't have any error message now.

Best Answer
0 Votes

Are you sure that async is implemented in this version of Jerryscript? I think the Fitbit version is basically ES5.1 with some exceptions.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

First the timeout error that I posted is just because my app was idle. So it has no relation to the error I'm getting. Sorry I posted that.

 

Regarding the error, it's really bizarre. I have no idea what is happening here. My app is def not that complicated for the stack to blow.  Yet, when I call one function with a simple console.log("hi"); and a console.log only the app closes. If I call the function without any code it works...

 

I also noticed that console.dir() doesn't work. Is there another way to debug other than with console.logs?? It's very limiting/hard to understand what is really crashing the app.

 

 

Thanks

 

Best Answer
0 Votes

Hi, Catplace

 

Thanks for replying. It works. I tested a simple function before I started developing and it did the trick.

 

Here:

 

async function initialize() {
    console.log('hi');
    await wait(1000*3);
    console.log('bye');
}
(async () => await initialize())();

The function that is crashing is a  sync one... I just posted another message saying more what is hapenning

Best Answer
0 Votes

Sorry for the red herring. I'm glad I'm wrong! 🙂

Peter McLennan
Gondwana Software
Best Answer
0 Votes

To be honest, that could be related. I really appreciate the input.

 

The code is very simple, like I said. I will try to refactor this week without the async/await functionality and only use timeouts and callbacks.

Best Answer
0 Votes

I refactored my code and I found several problems with the JS spec with the fitbit JS engine.

 

  1. Async/await work for some cases, but it is not reliable. As soon as you use it with events and the event trigger the async functions the app closes. Solution: Use Promises
  2. prototype.apply doesn't work
  3. Function calls have to have the exactly number of arguments which they were defined; which means using  to be called with the arguments they which I can see why this was implemented this way, but I had to use callbacks and with callbacks it can be hard to use the same amount of arguments (some functions have arguments, some don't have). Which leads to problem 4
  4. prototype.splice doesn't work if the number supplied is greater than the number of elements.

For problems 2,3, and 4 the function executing the app just dies silently; there is no error. I managed to circumvent all of them, but it was not fun

Best Answer
0 Votes

1. I'm not sure what you mean here, async/await is just another way of using Promises, as an alternative to then/catch.

2. What problem are you having with Function.prototype.apply?

3. Do you have some code that reproduces this issue?

4. Same for this too.

Best Answer
0 Votes

Liam,

 

  1. You are right. I had to remove the 'async' statements and use 'then' instead. For some reason using with an onclick event was not working, though.

I couldn't reproduce 2,3, and 4. It was probably something I did wrong and unfortunately I don't have the code anymore to verify this. To be honest, when trying to reproduce, I noticed that I was trying to use '.splice()' in one Object instead of in one Array and I believe that was the big problem here. I'm just surprised it was not throwing any error (now it is throwing errors). 

 

Thanks!

Best Answer
0 Votes