limiting how long a method is permiited to run



Hello all,

Is there a means of limiting how long a method is permiited to run? I
want to be able to mark a method with a number and have the method
throw, say, a TooMuchTimeException if the running time exceeds this
number.

I am envisioning declaratively applying such limits, either in the
class definition or setting the limits on individual objects.

Example: class Foo has instance methods calc1, cal2, etc. Depending
on the state of the foo object and the parameters passed into the
methods, these methods might run in a fraction of the second or they
might take minutes.

class Foo
def calc1
#complex work ...
end

def calc2(a, b)
#more complex work ...
end

#declare maximum time limit like this...
#TooMuchTimeException exception to be thrown if method takes too long
time_limit :calc1=>5, :calc2=>20
end

Is there anything already written that does this type of thing?

Thanks.

--Brian Buckley


.