Ruby code block timeout after n * milli * seconds

In Ruby, I need to disable code block execution after n milliseconds. I know that the Ruby Timeout library supports timeouts in seconds:

http://ruby-doc.org/stdlib/libdoc/timeout/rdoc/index.html

Is it possible?

+5
source share
1 answer

Just use the decimal value for the timeout. Example for n milliseconds:

Timeout::timeout(n / 1000.0) { sleep(100) }
+9
source

All Articles