Sha256: 3fadc4b47f3c30bf70671139a717def262e7bd09be30252f01dbbeb0e57d077f

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

#
# This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

require "lazier"
require "brauser"
require "interactor"
require "addressable/uri"
require "rack/utils"
require "rack/fiber_pool"
require "em-synchrony"
require "oj"

Lazier.load!
Oj.default_options = Oj.default_options.merge(mode: :compat, indent: 2, symbol_keys: true)

require "ballast/version" if !defined?(Ballast::Version)
require "ballast/errors"
require "ballast/context"
require "ballast/operation"
require "ballast/operations_chain"
require "ballast/request_domain_matcher"
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"

module Ballast
  # If running under eventmachine, run the block in a thread of its threadpool using EM::Synchrony, otherwise run the block normally.
  #
  # @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
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ballast-1.9.3 lib/ballast.rb