1 /*
2  * DSFML - The Simple and Fast Multimedia Library for D
3  *
4  * Copyright (c) 2013 - 2018 Jeremy DeHaan (dehaan.jeremiah@gmail.com)
5  *
6  * This software is provided 'as-is', without any express or implied warranty.
7  * In no event will the authors be held liable for any damages arising from the
8  * use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not claim
15  * that you wrote the original software. If you use this software in a product,
16  * an acknowledgment in the product documentation would be appreciated but is
17  * not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  * misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source distribution
23  *
24  *
25  * DSFML is based on SFML (Copyright Laurent Gomila)
26  */
27 
28 /// A module containing the sleep function.
29 module nudsfml.system.sleep;
30 
31 public import nudsfml.system.time;
32 
33 /**
34  * Make the current thread sleep for a given duration.
35  *
36  * sleep is the best way to block a program or one of its threads, as it doesn't
37  * consume any CPU power.
38  *
39  * Params:
40  *		duration = The length of time to sleep for
41  */
42 void sleep(Time duration)
43 {
44 	import core.thread: Thread;
45 	import core.time: usecs;
46 	Thread.sleep(usecs(duration.asMicroseconds()));
47 }
48 
49 unittest
50 {
51 	version(DSFML_Unittest_System)
52 	{
53 		import std.stdio;
54 
55 		writeln("Unit test for sleep function");
56 
57 		writeln("Start!(sleeping for 1 second)");
58 		sleep(seconds(1));
59 		writeln("Done! Now sleeping for 2 seconds.");
60 		sleep(seconds(2));
61 		writeln("Done! I think you get the idea.");
62 		writeln();
63 	}
64 }