Skip to content
Browse files

add EventMachine.defers_finished?

  • Loading branch information...
1 parent 86e38e4 commit c36b0b045c9000e48ce6974a3f28a585cf2522fd @paddor paddor committed Apr 19, 2012
Showing with 16 additions and 1 deletion.
  1. +16 −1 lib/eventmachine.rb
View
17 lib/eventmachine.rb
@@ -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
@@ -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 = []
@@ -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

0 comments on commit c36b0b0

Please sign in to comment.
Something went wrong with that request. Please try again.