Thread::wait() question


#1

Is it possible to use Thread::wait() to add a delay in when some code is executed inside the run() method?

e.g.

void MyThread::run() override {
     auto tStart = juce::Time::currentTimeMillis();
     DBG( "somemessage" );
     wait(500);  //wait 0.5 seconds
     //hopefully this line is executed 0.5 seconds later
     DBG( "delay " + String( juce::Time::currentTimeMillis() - tStart ) ); 
}

#2

Yes. But bear in mind it could return early if something interrupts it, like the thread trying to stop.