Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #316 from paddor/master

Add EventMachine.defers_finished?
  • Loading branch information...
commit a92b667684ed17602fa91915e9095c1d7710ba43 2 parents cc9a3ad + fe2a94d
James Tucker raggi authored
Showing with 16 additions and 2 deletions.
  1. +16 −2 lib/eventmachine.rb
18 lib/eventmachine.rb
View
@@ -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 = []
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.