From 0a778a54d63ce49adcfb1919de362722b98d4bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 20 Dec 2013 10:58:20 +0100 Subject: [PATCH] Add an example and a notice about interaction with other tasks to sleep(). Fixes #434. --- source/vibe/core/core.d | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index 0548fc7bf2..0c4d308382 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -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) { @@ -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."); + } +} /**