Sha256: 44e3ffef1bd01ce87f999576021b9119cae94e8008103a43b0720b39c33f381d
Contents?: true
Size: 670 Bytes
Versions: 5
Compression:
Stored size: 670 Bytes
Contents
# based on Timeout module ContiniousTimeout class TimeoutException < ::Exception end class RestartException < ::Exception end class Deferer def initialize(thread) @thread = thread end def defer @thread.raise RestartException.new end end def self.timeout(sec) begin x = Thread.current y = Thread.start do 1.times do begin sleep sec rescue RestartException => e retry end end x.raise TimeoutException, "execution expired" if x.alive? end yield Deferer.new(y) ensure y.kill if y and y.alive? end end end
Version data entries
5 entries across 5 versions & 1 rubygems