C
Chuckl
This idiom has been a decent shortcut for my work:
require 'timeout'
def timeout?(sec)
begin
freq = [0.01, sec / 1000].max
timeout(sec) {
while true
return false if yield
sleep(freq)
end
}
rescue Timeout::Error
return true
end
end
Code police may even approve, since 'timeout.rb' kinda uses
exception-throwing as flow control.
require 'timeout'
def timeout?(sec)
begin
freq = [0.01, sec / 1000].max
timeout(sec) {
while true
return false if yield
sleep(freq)
end
}
rescue Timeout::Error
return true
end
end
Code police may even approve, since 'timeout.rb' kinda uses
exception-throwing as flow control.