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.
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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 AnswerHi, 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 AnswerAre you sure that async is implemented in this version of Jerryscript? I think the Fitbit version is basically ES5.1 with some exceptions.
Best AnswerFirst 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 AnswerHi, 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 AnswerTo 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 AnswerI refactored my code and I found several problems with the JS spec with the fitbit JS engine.
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
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
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 AnswerLiam,
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