It's valid but problematic for debugging, performance and reading clarity.
Can you use
void updateState() {
// do some stuff before
while (this.timeReference.isAfter(lastInterval.getBeggining())
{
this.timeReference = lastInterval.getEnd();
lastInterval = intervalIterator.next();
}
// do more stuff after
}
instead if maybeUpdateTime()
is only called by updateState()
? If it's called by other functions, the condition in while
could be wrapped to maybeUpdateTime()
and inside the loop it is wrapped to updateTime()
.
Or if you have performance requirements and don't want to (1) consume more CPU resources, (2) block other tasks in the same thread, maybe consider put maybeUpdateTime()
into a separate thread that allows you to wait for a task to complete (update time).