public boolean wait_timeout(IRubyObject o, Double timeout) throws InterruptedException { if (timeout != null) { long delay_ns = (long) (timeout.doubleValue() * 1000000000.0); long start_ns = System.nanoTime(); if (delay_ns > 0) { long delay_ms = delay_ns / 1000000; int delay_ns_remainder = (int) (delay_ns % 1000000); executeBlockingTask(new SleepTask(o, delay_ms, delay_ns_remainder)); } long end_ns = System.nanoTime(); return (end_ns - start_ns) <= delay_ns; } else { executeBlockingTask(new SleepTask(o, 0, 0)); return true; } }