Move the spawn code out of the poll method.

This commit is contained in:
Danila Fedorin 2018-01-12 22:07:32 -08:00
parent caca0b1398
commit d020c0c9bf

View File

@ -84,34 +84,38 @@ module Telepathy
end end
end end
private def spawn_workers
spawn do
loop do
action = @poll_channel.receive
case action
when Int64?
@last_update_id = action.nil? ? @last_update_id : action + 1
@update_channel.send get_updates 10
when Control
@update_channel.send action
break
end
end
end
spawn do
loop do
item = @update_channel.receive
case item
when Array(Update)
process_updates(item)
@poll_channel.send item.last?.try &.update_id
when Control
break
end
end
end
end
def poll def poll
if !@poll_running if !@poll_running
@poll_running = true @poll_running = true
spawn do spawn_workers
loop do
action = @poll_channel.receive
case action
when Int64?
@last_update_id = action.nil? ? @last_update_id : action + 1
@update_channel.send get_updates 10
when Control
@update_channel.send action
break
end
end
end
spawn do
loop do
item = @update_channel.receive
case item
when Array(Update)
process_updates(item)
@poll_channel.send item.last?.try &.update_id
when Control
break
end
end
end
end end
@poll_channel.send nil @poll_channel.send nil
end end