Skip to content

Commit

Permalink
Merge pull request #9 from centosadmin/nested-handlers
Browse files Browse the repository at this point in the history
Fix recursive locking in nested handlers
  • Loading branch information
vladislav-yashin authored May 16, 2018
2 parents be3d17c + 9a66dcc commit 096ff99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/tdlib/update_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def stopped?

def handle_update
update = TD::Api.client_receive(@td_client, TIMEOUT)
@mutex.synchronize do
@handlers.each { |h| h.call(update) } unless update.nil?
end
@mutex.synchronize { handlers = @handlers.dup }
handlers.each { |h| h.call(update) } unless update.nil?
end
end
15 changes: 15 additions & 0 deletions spec/integration/tdlib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,19 @@
expect(@result).to include('@type', 'entities')
end
end

describe 'nested handlers' do
before { Thread.abort_on_exception = true }

subject do
client.on_ready do
client.broadcast(payload) do
client.broadcast_and_receive(payload)
end
sleep 1
end
end

it { expect { subject }.not_to raise_error(Exception) }
end
end

0 comments on commit 096ff99

Please sign in to comment.