0

I have a variable which is going to help me check if 10 seconds has passed.

private val currTime: Long = System.currentTimeMillis()
private val time: Long = 10000

I want something where, if a function foo is called, it will reset currTime to be the current time. That's the easy part which I can do. The tough part, and part 2 of this, is that if currTime at any point exceeds time, I want to change a boolean (say isHappy) from true to false - this can be in a function called bar.

I come from C#, so i'm not sure how to do this - typically we'd use a dispatcher timer but i have no idea how to achieve this is Scala.

I've seen scheduler examples and fixed interval examples, but this is more of a moving target... a condition that can be met at any time.

In simpler terms, it's like having 2 ints. Int A and Int B. When the sum of A and B is over 10, a function is triggered. A and B are forever changing in different functions in that class. How can we create a trigger?

Susssshi
  • 33
  • 4
  • 1
    Does this answer your question? [Run a function periodically in Scala](https://stackoverflow.com/questions/25351186/run-a-function-periodically-in-scala) – smac89 Jan 27 '21 at 20:07
  • potentially partially. If `foo` is called and resets `currTime`, how will the timer know to continue waiting until `currTime` is > than `time`? – Susssshi Jan 27 '21 at 20:09

0 Answers0