Sha256: 51623189babb1fe3d58ae8b7b0a425754176c76bcbc3a3bb4df594652d378a98
Contents?: true
Size: 780 Bytes
Versions: 1
Compression:
Stored size: 780 Bytes
Contents
# based on Timeout class DumpRake # Timeout if does not finish or defer in requested time module ContiniousTimeout class TimeoutException < ::Exception; end class RestartException < ::Exception; end # Object with defer method class Deferer def initialize(thread) @thread = thread end def defer @thread.raise RestartException.new end end def self.timeout(sec) x = Thread.current y = Thread.start do 1.times do begin sleep sec rescue RestartException retry end end x.raise TimeoutException, 'execution expired' if x.alive? end yield Deferer.new(y) ensure y.kill if y && y.alive? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dump-1.0.5 | lib/dump_rake/continious_timeout.rb |