Skip to content

Commit

Permalink
Add an example and a notice about interaction with other tasks to sle…
Browse files Browse the repository at this point in the history
…ep(). Fixes #434.
  • Loading branch information
s-ludwig committed Dec 20, 2013
1 parent 875cdf1 commit 0a778a5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/vibe/core/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ void rawYield()

/**
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 $(D core.thread.Thread.sleep), which shouldn't be
used in vibe.d applications.
*/
void sleep(Duration timeout)
{
Expand All @@ -286,6 +290,19 @@ void sleep(Duration timeout)
tm.wait();
destroy(tm);
}
///
unittest {
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.");
}
}


/**
Expand Down

0 comments on commit 0a778a5

Please sign in to comment.