1

I have this while loop:

while (now() > timeToday(checkTime).time && now() < timeToday(arrivalTime).time){

I would like for this loop to run only when the real time clock's seconds hits 00 Basically allowing the loop to run once per minute. I am doing this because the IDE I am writing in only allows a 15 second pause maximum. Unfortunately sleep() is not an option at all in the SmartThings IDE

I was thinking something like this

while (now() > timeToday(checkTime).time && 
       now() < timeToday(arrivalTime).time && 
       Date.parse('ss', now() = 00).time){

But I'm fumbling with it.

If there is a better way to do this than the conditional please let me know.

Jeff Beck
  • 3,944
  • 3
  • 28
  • 45
Brian
  • 622
  • 10
  • 29

3 Answers3

2

For scenarios like "once a minute" , You may take a look at TimerTask which can be easily used in groovy way.

new Timer().schedule({
    // your logic here
} as TimerTask, startTime, 1000) 

I would recommend reading the javadoc thoroughly to understand the scheduling contract (correctness of tick).

kdabir
  • 9,623
  • 3
  • 43
  • 45
2

SmartThings finally gave an answer back and said to use their runIn(60, myHandler) logic.

Thanks for everyones input.

Brian
  • 622
  • 10
  • 29
1

You could try sleep 60*1000 to sleep for a minute in a loop before iterating over next cycle

while true
{
  sleep 60*1000
  //do your stuff here
  //make sure to include break logic to exit out of the loop
}
suman j
  • 6,710
  • 11
  • 58
  • 109