Class: Telegram::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/authorization.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Watcher

Returns a new instance of Watcher.



81
82
83
84
# File 'lib/telegram/authorization.rb', line 81

def initialize(&block)
  @thread = nil
  @block = block
end

Instance Method Details

#call_after(sec) ⇒ Object



86
87
88
89
# File 'lib/telegram/authorization.rb', line 86

def call_after(sec)
  stop
  @thread = Thread.new { sleep(sec); @block.call }
end

#stopObject



91
92
93
# File 'lib/telegram/authorization.rb', line 91

def stop
  @thread.exit if @thread && @thread.alive?
end