In Ruby I would use the Timeout module, where it executes a block and will stop executing the code if it passes the timeout.
require 'timeout'
status = Timeout::timeout(5) {
# Something that should be interrupted if it takes too much time...
}
Does Groovy have something like this?
There is the
TimedInterrupt
annotation, but I've not tried it out yet...Gave it a quick test, and this (poor example):
Runs in the groovy console and prints out
i
after 5 seconds.I get: