sleep

Suspends the execution of the calling task for the specified amount of time.

Note that other tasks of the same thread will continue to run during the wait time, in contrast to core.thread.Thread.sleep, which shouldn't be used in vibe.d applications.

More...
@safe
void
sleep
(
Duration timeout
)

Detailed Description

Repeated sleep

As this method creates a new Timer every time, it is not recommended to use it in a tight loop. For functions that calls sleep frequently, it is preferable to instantiate a single Timer and reuse it, as shown in the following example:

	  void myPollingFunction () {
		  Timer waiter = createTimer(null); // Create a re-usable timer
		  while (true) {
			  // Your awesome code goes here
			  timer.rearm(timeout, false);
			  timer.wait();
		  }
	  }

Throws

May throw an InterruptException if the task gets interrupted using Task.interrupt().

Examples

import vibe.core.core : sleep;
import vibe.core.log : logInfo;
import core.time : msecs;

void test()
{
	logInfo("Sleeping for half a second...");
	sleep(500.msecs);
	logInfo("Done sleeping.");
}

Meta