Skip to content

Commit

Permalink
add EventMachine.defers_finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
paddor committed Apr 19, 2012
1 parent 86e38e4 commit c36b0b0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion 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 @@ -1038,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 unless @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 c36b0b0

Please sign in to comment.