How to properly Thread.sleep?
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 25 10:29:28 PDT 2015
On 03/25/2015 10:23 AM, Israel wrote:
> Ive tried using google but no matter what code i find it either doesnt
> work, compiler gives me errors or maybe the code is deprecated.
>
> What is the proper way of adding sleep time to a program?
> Ive tried..
>
> import std.stdio;
> import core.thread;
>
> void main()
> {
> writeln("Sleep..");
> sleep(200);
Replace that with
Thread.sleep(200.msecs);
> writeln("done");
> }
>
> but all i get is a compiler error unidentified identifier sleep.
>
> The documentation examples dont make sense.
Here is alternative documentation:
http://ddili.org/ders/d.en/parallelism.html#ix_parallelism.Thread.sleep
> hy would it work this way?
>
> Thread.sleep( dur!("msecs")( 50 ) ); // sleep for 50 milliseconds
> Thread.sleep( dur!("seconds")( 5 ) ); // sleep for 5 seconds
UFCS makes it easier by making those 50.msecs and 5.seconds.
Ali
More information about the Digitalmars-d-learn
mailing list