Module: Ballast

Defined in:
lib/ballast.rb,
lib/ballast/emoji.rb,
lib/ballast/errors.rb,
lib/ballast/service.rb,
lib/ballast/version.rb,
lib/ballast/ajax_response.rb,
lib/ballast/concerns/view.rb,
lib/ballast/configuration.rb,
lib/ballast/concerns/common.rb,
lib/ballast/concerns/ajax_handling.rb,
lib/ballast/request_domain_matcher.rb,
lib/ballast/concerns/errors_handling.rb,
lib/ballast/middlewares/default_host.rb,
lib/ballast/concerns/json_api/request_handling.rb,
lib/ballast/concerns/json_api/response_handling.rb,
lib/ballast/concerns/json_api/pagination_handling.rb

Overview

This file is part of the ballast gem. Copyright (C) 2013 and above Shogun [email protected]. Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/mit.

Defined Under Namespace

Modules: Concerns, Emoji, Errors, Middlewares, Version Classes: AjaxResponse, Configuration, RequestDomainMatcher, Service

Class Method Summary collapse

Class Method Details

.in_em_thread(start_reactor = false, &block) ⇒ Object

If running under eventmachine, runs the block in a thread of its threadpool using EM::Synchrony, otherwise runs the block directly.

Parameters:

  • start_reactor (Boolean) (defaults to: false)

    If start a EM::Synchrony reactor if none is running.

  • block (Proc)

    The block to run.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ballast.rb', line 38

def self.in_em_thread(start_reactor = false, &block)
  if EM.reactor_running?
    run_in_thread(&block)
  elsif start_reactor
    EM.synchrony do
      Ballast.in_em_thread(&block)
      EM.stop
    end
  else
    block.call
  end
end

.run_in_thread(&block) ⇒ Object

:nodoc:



52
53
54
55
56
# File 'lib/ballast.rb', line 52

def self.run_in_thread(&block)
  EM::Synchrony.defer do
    Fiber.new { block.call }.resume
  end
end