module Resqued::Sleepy

Public Instance Methods

awake() click to toggle source

Public: Break out of ‘yawn`.

# File lib/resqued/sleepy.rb, line 18
def awake
  self_pipe[1].kgio_trywrite(".")
end
self_pipe() click to toggle source

Private.

# File lib/resqued/sleepy.rb, line 23
def self_pipe
  @self_pipe ||= Kgio::Pipe.new.each { |io| io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) }
end
yawn(duration, *inputs) click to toggle source

Public: Like sleep, but the sleep is interrupted if input is detected on one of the provided IO objects, or if ‘awake` is called (e.g. from a signal handler).

# File lib/resqued/sleepy.rb, line 9
def yawn(duration, *inputs)
  if duration > 0
    inputs = [self_pipe[0]] + [inputs].flatten.compact
    IO.select(inputs, nil, nil, duration) or return
    self_pipe[0].kgio_tryread(11)
  end
end