Skip to content

Commit

Permalink
Fix 100% cpu in async examples
Browse files Browse the repository at this point in the history
This switches from the endless loop to accumulating and joining the
threads.
  • Loading branch information
felixbuenemann committed Apr 29, 2018
1 parent 54fed17 commit 6ee4434
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.11.2 (Next)

* Your contribution here.
* [#206](https://github.com/slack-ruby/slack-ruby-client/pull/206): Fix 100% cpu usage in async examples - [@felixbuenemann](https://github.com/felixbuenemann).

### 0.11.1 (1/23/2017)

Expand Down
7 changes: 3 additions & 4 deletions examples/hi_real_time_async_celluloid/hi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$stdout.sync = true
logger = Logger.new($stdout)
logger.level = Logger::DEBUG
threads = []

ENV['SLACK_API_TOKENS'].split.each do |token|
logger.info "Starting #{token[0..12]} ..."
Expand All @@ -28,9 +29,7 @@
end
end

client.start_async
threads << client.start_async
end

loop do
Thread.pass
end
threads.each(&:join)
7 changes: 3 additions & 4 deletions examples/hi_real_time_async_eventmachine/hi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$stdout.sync = true
logger = Logger.new($stdout)
logger.level = Logger::DEBUG
threads = []

ENV['SLACK_API_TOKENS'].split.each do |token|
logger.info "Starting #{token[0..12]} ..."
Expand All @@ -28,9 +29,7 @@
end
end

client.start_async
threads << client.start_async
end

loop do
Thread.pass
end
threads.each(&:join)

0 comments on commit 6ee4434

Please sign in to comment.