01-09-2019 06:58 - edited 01-09-2019 07:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-09-2019 06:58 - edited 01-09-2019 07:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-09-2019 09:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-09-2019 15:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-09-2019 15:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Are you sure that async is implemented in this version of Jerryscript? I think the Fitbit version is basically ES5.1 with some exceptions.
Gondwana Software

01-09-2019 16:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-09-2019 16:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-09-2019 16:21
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-09-2019 16:28
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Sorry for the red herring. I'm glad I'm wrong! 🙂
Gondwana Software

01-09-2019 16:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-09-2019 16:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-12-2019 11:17 - edited 01-12-2019 11:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I refactored my code and I found several problems with the JS spec with the fitbit JS engine.
- 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
- prototype.apply doesn't work
- 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
- 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

01-14-2019 13:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



01-14-2019 13:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-17-2019 15:49
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Liam,
- 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!

