Skip to content

Commit

Permalink
Remove Mutex in favor of make_true
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Cantero committed Dec 19, 2016
1 parent 3bad1e0 commit 9b9d4b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/default_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class DefaultWorker
shoryuken_options queue: 'default', auto_delete: true

def perform(sqs_msg, body)
Shoryuken.logger.info("Received message: '#{body}'")
Shoryuken.logger.debug("Received message: '#{body}'")
end
end
12 changes: 5 additions & 7 deletions lib/shoryuken/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(fetcher, polling_strategy)

@done = Concurrent::AtomicBoolean.new(false)

@dispatch_later_mutex = Mutex.new
@dispatch_later = Concurrent::AtomicBoolean.new(false)

@fetcher = fetcher
@polling_strategy = polling_strategy
Expand Down Expand Up @@ -84,13 +84,11 @@ def busy
end

def dispatch_later
return if @_dispatch_later
return unless @dispatch_later.make_true

@dispatch_later_mutex.synchronize do
@_dispatch_later ||= after(1) do
@_dispatch_later = nil
dispatch
end
after(1) do
@dispatch_later.make_false
dispatch
end
end

Expand Down

0 comments on commit 9b9d4b3

Please sign in to comment.