Sha256: 764beca9d88822d16eb95239f3d567e32e46f229305f8d4453bc85cf216adaab
Contents?: true
Size: 686 Bytes
Versions: 8
Compression:
Stored size: 686 Bytes
Contents
module Delayed module Runnable def start trap('TERM') { quit! } trap('INT') { quit! } say "Starting #{self.class.name}" Delayed.lifecycle.run_callbacks(:execute, nil) do loop do run! break if stop? end end ensure on_exit! end private def on_exit!; end def interruptable_sleep(seconds) pipe[0].wait_readable(seconds) end def stop pipe[1].close end def stop? pipe[1].closed? end def quit! Thread.new { say 'Exiting...' }.tap do |t| stop t.join end end def pipe @pipe ||= IO.pipe end end end
Version data entries
8 entries across 8 versions & 1 rubygems