diff --git a/lib/telegram/bot/updates_poller.rb b/lib/telegram/bot/updates_poller.rb index c5810aa..6623e1c 100644 --- a/lib/telegram/bot/updates_poller.rb +++ b/lib/telegram/bot/updates_poller.rb @@ -41,19 +41,25 @@ module Telegram def start return if running - @running = true - log { 'Started bot poller.' } - while running - begin - updates = fetch_updates - process_updates(updates) if updates && updates.any? - rescue Interrupt - @running = false - end + begin + @running = true + log { 'Started bot poller.' } + run + rescue Interrupt + nil # noop + ensure + @running = false end log { 'Stoped polling bot updates.' } end + def run + while running + updates = fetch_updates + process_updates(updates) if updates && updates.any? + end + end + # Method to stop poller from other thread. def stop return unless running