Class: Rpush::Daemon::InterruptibleSleep

Inherits:
Object
  • Object
show all
Defined in:
lib/rpush/daemon/interruptible_sleep.rb

Instance Method Summary collapse

Instance Method Details

#sleep(duration) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rpush/daemon/interruptible_sleep.rb', line 4

def sleep(duration)
  @thread = Thread.new { Kernel.sleep duration }
  Thread.pass

  begin
    @thread.join
  rescue StandardError # rubocop:disable Lint/HandleExceptions
  ensure
    @thread = nil
  end
end

#stopObject



16
17
18
19
20
21
# File 'lib/rpush/daemon/interruptible_sleep.rb', line 16

def stop
  @thread.kill if @thread
rescue StandardError # rubocop:disable Lint/HandleExceptions
ensure
  @thread = nil
end