sleep
ErrorsCollection

sleep

Synthesised documentation from type/Date

From type/Date

See Original text in context

sub sleep($seconds = Inf --> Nil)

Attempt to sleep for the given number of $seconds. Returns Nil on completion. Accepts Int, Num, Rat, or Duration types as an argument since all of these also do Real.

sleep 5;                # Int 
sleep 5.2;              # Num 
sleep (5/2);            # Rat 
sleep (now - now + 5);  # Duration 

It is thus possible to sleep for a non-integer amount of time. For instance, the following code shows that sleep (5/2) sleeps for 2.5 seconds and sleep 5.2 sleeps for 5.2 seconds:

my $before = now;
sleep (5/2);
my $after = now;
say $after-$before;  # OUTPUT: «2.502411561␤» 
 
$before = now;
sleep 5.2;
$after = now;
say $after-$before;  # OUTPUT: «5.20156987␤»