Skip to content

Commit

Permalink
Merge pull request eventmachine#316 from paddor/master
Browse files Browse the repository at this point in the history
Add EventMachine.defers_finished?
  • Loading branch information
raggi committed Apr 21, 2012
2 parents cc9a3ad + fe2a94d commit a92b667
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/eventmachine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class << self
@reactor_running = false
@next_tick_queue = []
@tails = []
@threadpool = nil
@threadpool = @threadqueue = @resultqueue = nil
@all_threads_spawned = false

# System errnos
# @private
Expand Down Expand Up @@ -208,6 +209,7 @@ def self.run blk=nil, tail=nil, &block
@threadqueue = nil
@resultqueue = nil
@threadpool = nil
@all_threads_spawned = false
end

@next_tick_queue = []
Expand Down Expand Up @@ -1014,7 +1016,6 @@ def self.defer op = nil, callback = nil, &blk
# has no constructor.

unless @threadpool
require 'thread'
@threadpool = []
@threadqueue = ::Queue.new
@resultqueue = ::Queue.new
Expand All @@ -1039,6 +1040,19 @@ def self.spawn_threadpool
end
@threadpool << thread
end
@all_threads_spawned = true
end

##
# Returns +true+ if all deferred actions are done executing and their
# callbacks have been fired.
#
def self.defers_finished?
return false if @threadpool and !@all_threads_spawned
return false if @threadqueue and not @threadqueue.empty?
return false if @resultqueue and not @resultqueue.empty?
return false if @threadpool and @threadqueue.num_waiting != @threadpool.size
return true
end

class << self
Expand Down

0 comments on commit a92b667

Please sign in to comment.