01-09-2019 06:58 - edited 01-09-2019 07:00
01-09-2019 06:58 - edited 01-09-2019 07:00
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.
01-09-2019 09:15
01-09-2019 09:15
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
01-09-2019 15:48
01-09-2019 15:48
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.
01-09-2019 15:57
01-09-2019 15:57
Are you sure that async is implemented in this version of Jerryscript? I think the Fitbit version is basically ES5.1 with some exceptions.
01-09-2019 16:16
01-09-2019 16:16
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
01-09-2019 16:21
01-09-2019 16:21
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
01-09-2019 16:28
01-09-2019 16:28
Sorry for the red herring. I'm glad I'm wrong! 🙂
01-09-2019 16:39
01-09-2019 16:39
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.
01-12-2019 11:17 - edited 01-12-2019 11:18
01-12-2019 11:17 - edited 01-12-2019 11:18
I 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
01-14-2019 13:01
01-14-2019 13:01
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.
01-17-2019 15:49
01-17-2019 15:49
Liam,
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!