sleep(...)
public
Suspends the current thread for duration seconds (which may be any
number, including a Float with
fractional seconds). Returns the actual number of seconds slept (rounded),
which may be less than that asked for if another thread calls Thread#run.
Zero arguments causes sleep to sleep forever.
Time.new
sleep 1.2
Time.new
sleep 1.9
Time.new
Show source
/*
* call-seq:
* sleep([duration]) => fixnum
*
* Suspends the current thread for _duration_ seconds (which may be any number,
* including a +Float+ with fractional seconds). Returns the actual number of
* seconds slept (rounded), which may be less than that asked for if another
* thread calls <code>Thread#run</code>. Zero arguments causes +sleep+ to sleep
* forever.
*
* Time.new
* sleep 1.2
* Time.new
* sleep 1.9
* Time.new
*/
static VALUE
rb_f_sleep(argc, argv)
int argc;
VALUE *argv;
{
int beg, end;
beg = time(0);
if (argc == 0) {
rb_thread_sleep_forever();
}
else if (argc == 1) {
rb_thread_wait_for(rb_time_interval(argv[0]));
}
else {
rb_raise(rb_eArgError, "wrong number of arguments");
}
end = time(0) - beg;
return INT2FIX(end);
}