Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 1 changed file with 16 additions and 2 deletions. Show diff stats Hide diff stats

  1. +16 2 lib/eventmachine.rb
18 lib/eventmachine.rb
@@ -82,7 +82,8 @@ class << self
82 82 @reactor_running = false
83 83 @next_tick_queue = []
84 84 @tails = []
85   - @threadpool = nil
  85 + @threadpool = @threadqueue = @resultqueue = nil
  86 + @all_threads_spawned = false
86 87
87 88 # System errnos
88 89 # @private
@@ -208,6 +209,7 @@ def self.run blk=nil, tail=nil, &block
208 209 @threadqueue = nil
209 210 @resultqueue = nil
210 211 @threadpool = nil
  212 + @all_threads_spawned = false
211 213 end
212 214
213 215 @next_tick_queue = []
@@ -1014,7 +1016,6 @@ def self.defer op = nil, callback = nil, &blk
1014 1016 # has no constructor.
1015 1017
1016 1018 unless @threadpool
1017   - require 'thread'
1018 1019 @threadpool = []
1019 1020 @threadqueue = ::Queue.new
1020 1021 @resultqueue = ::Queue.new
@@ -1039,6 +1040,19 @@ def self.spawn_threadpool
1039 1040 end
1040 1041 @threadpool << thread
1041 1042 end
  1043 + @all_threads_spawned = true
  1044 + end
  1045 +
  1046 + ##
  1047 + # Returns +true+ if all deferred actions are done executing and their
  1048 + # callbacks have been fired.
  1049 + #
  1050 + def self.defers_finished?
  1051 + return false if @threadpool and !@all_threads_spawned
  1052 + return false if @threadqueue and not @threadqueue.empty?
  1053 + return false if @resultqueue and not @resultqueue.empty?
  1054 + return false if @threadpool and @threadqueue.num_waiting != @threadpool.size
  1055 + return true
1042 1056 end
1043 1057
1044 1058 class << self

0 comments on commit a92b667

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