Sha256: a7fac8a44be849430cf8fd76c24238d79d4c21aab7cf5a8596dae13bba57fa20
Contents?: true
Size: 779 Bytes
Versions: 1
Compression:
Stored size: 779 Bytes
Contents
# based on Timeout module Dump # Timeout if does not finish or defer in requested time module ContiniousTimeout class TimeoutException < RuntimeError; end class RestartException < RuntimeError; 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.2.0 | lib/dump/continious_timeout.rb |