Module: Resqued::Sleepy

Included in:
Listener, Master
Defined in:
lib/resqued/sleepy.rb

Instance Method Summary collapse

Instance Method Details

#awakeObject

Public: Break out of ‘yawn`.



18
19
20
# File 'lib/resqued/sleepy.rb', line 18

def awake
  self_pipe[1].kgio_trywrite(".")
end

#self_pipeObject

Private.



23
24
25
# 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) ⇒ Object

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).



9
10
11
12
13
14
15
# 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