Skip to content

Commit 65ceaa5

Browse files
committed
Refactor poller module to extract poll_and_dispatch method. Improves code readability and maintainability.
1 parent 82c2b38 commit 65ceaa5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/tourmaline/poller.cr

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,24 @@ module Tourmaline
1818
Log.info { "Polling for updates..." }
1919
@polling = true
2020
while @polling
21-
updates = @client.get_updates(offset: offset, timeout: 30)
22-
updates.each do |update|
23-
@client.dispatcher.process(update)
24-
@offset = Int64.new(update.update_id + 1)
25-
end
21+
poll_and_dispatch
2622
end
2723
end
2824

2925
def stop
3026
@polling = false
3127
end
28+
29+
def poll_and_dispatch
30+
updates = get_updates
31+
updates.each do |update|
32+
@client.dispatcher.process(update)
33+
@offset = Int64.new(update.update_id + 1)
34+
end
35+
end
36+
37+
def get_updates
38+
@client.get_updates(offset: offset, timeout: 30)
39+
end
3240
end
3341
end

0 commit comments

Comments
 (0)