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



16
17
18
# File 'lib/resqued/sleepy.rb', line 16

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

#self_pipeObject

Private.



21
22
23
# File 'lib/resqued/sleepy.rb', line 21

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



7
8
9
10
11
12
13
# File 'lib/resqued/sleepy.rb', line 7

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