lib/ballast.rb in ballast-1.9.2 vs lib/ballast.rb in ballast-1.9.3

- old
+ new

@@ -33,18 +33,26 @@ # # @param start_reactor [Boolean] If start a EM::Synchrony reactor if none is running. # @param block [Proc] The block to run. def self.in_em_thread(start_reactor = false, &block) if EM.reactor_running? then - EM::Synchrony.defer do - Fiber.new { block.call }.resume - end + run_in_thread(&block) elsif start_reactor then EM.synchrony do Ballast.in_em_thread(&block) EM.stop end else block.call end end + + private + # Runs a block inside a EM thread. + # + # @param block [Proc] The block to run. + def self.run_in_thread(&block) + EM::Synchrony.defer do + Fiber.new { block.call }.resume + end + end end \ No newline at end of file