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?
question from:
https://stackoverflow.com/questions/65926570/call-a-function-every-x-seconds-when-activated-scala 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…