lib/ballast.rb in ballast-1.7.0 vs lib/ballast.rb in ballast-1.8.0

- old
+ new

@@ -24,6 +24,21 @@ require "ballast/configuration" require "ballast/concerns/ajax" require "ballast/concerns/common" require "ballast/concerns/view" require "ballast/concerns/errors_handling" -require "ballast/middlewares/default_host" +require "ballast/middlewares/default_host" + +module Ballast + # If running under eventmachine, run the block in a thread of its threadpool using EM::Synchrony, otherwise run the block normally. + # + # @param block [Proc] The block to run. + def self.in_em_thread(&block) + if EM.reactor_running? then + EM::Synchrony.defer do + Fiber.new { block.call }.resume + end + else + block.call + end + end +end \ No newline at end of file