Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));

Marcone marcone at email.com
Tue Nov 12 22:40:20 UTC 2019


On Tuesday, 12 November 2019 at 22:26:48 UTC, Daniel Kozak wrote:
> On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote:
>> I am using this function to sleep, but I want a simple Alias. 
>> How can I alias this?
>>
>> // Function sleep(int)
>> void sleep(int seconds){
>> 	Thread.sleep(dur!("seconds")( seconds ));
>> }
>>
>> sleep(1); // Using function.
>
> You can do this:
>
> import std.functional;
> import core.time;
> import core.thread;
>
> alias sleep = compose!(Thread.sleep, dur!("seconds"));
>
> void main()
> {
>     sleep(10);
> }

Daniel Kozak Thank you very much! It works very well!


More information about the Digitalmars-d-learn mailing list