Move the spawn code out of the poll method.
This commit is contained in:
parent
caca0b1398
commit
d020c0c9bf
|
@ -84,34 +84,38 @@ module Telepathy
|
|||
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
|
||||
if !@poll_running
|
||||
@poll_running = true
|
||||
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
|
||||
spawn_workers
|
||||
end
|
||||
@poll_channel.send nil
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user