4

I'm building an app for the Pebble watch using Pebble.js in cloudpebble.

When I look at the Javascript tips & tricks there is a really big heading that says:

Do not use setInterval(). And of course, do not use setTimeout() to simulate intervals.

As an alternative.. It does say

If you need some function to run at regular intervals, set a timer on Pebble and send a message to the JavaScript. If the JavaScript is dead, the mobile app will re-initialize it and run the message handler.

But I can't find any way to do this with pure javascript

Do you guys have any experience with this?

admdrew
  • 3,790
  • 4
  • 27
  • 39
Tim
  • 307
  • 1
  • 3
  • 13
  • 1
    I think those tips are meant for Pebblekit which is a companion to C SDK. I currently don't see a different way to set up a repeating process in pure Pebble.js. – Yuriy Galanter Oct 17 '14 at 21:23

2 Answers2

3

The advice we gave about setInterval() applied in the early days but not anymore. Feel free to use setInterval() now, your JavaScript will run properly as long as your app is running.

Of course, every time your JavaScript wakes up it will use some battery on the phone. And even more battery if you communicate with the watch. Be aware of the battery impact. This is true for both PebbleKit JS and Pebble.js.

In Pebble.js, if you just want to update the time on the screen, you can use the TimeText Element.

sarfata
  • 4,625
  • 4
  • 28
  • 36
0

I stand corrected. Since Pebble.js actual Javascript code runs on your phone, currently there's no reliable way to keep JS interval running (since the code can be shut down at any time). So the only reliable way to do it is via watchapp written in C that actually runs on Pebble (and it still can interact with JS code on the phone)

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136