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
# 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
    @thread = nil
  end
end

#stopObject



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

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