Module: RailsDevelopmentBoost::Async

Extended by:
Async
Included in:
Async
Defined in:
lib/rails_development_boost/async.rb,
lib/rails_development_boost/async/reactor.rb

Defined Under Namespace

Modules: Reactor Classes: Middleware

Constant Summary collapse

MONITOR =
Monitor.new

Instance Method Summary collapse

Instance Method Details

#enable_by_default!(user_provided_value = false) ⇒ Object



68
69
70
71
72
73
# File 'lib/rails_development_boost/async.rb', line 68

def enable_by_default!(user_provided_value = false)
  unless user_provided_value
    DependenciesPatch.async = true unless usable? # trigger the warning message, unless there is a user supplied `async` setting
    DependenciesPatch.async = !in_console?
  end
end

#heartbeat_check!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rails_development_boost/async.rb', line 24

def heartbeat_check!
  if @reactor
    unless @reactor.alive_and_watching?(ActiveSupport::Dependencies.autoload_paths)
      @reactor.stop
      @reactor = nil
      start!
    end
    re_raise_unload_error_if_any
  else
    start!
  end
  @unloaded_something.tap { @unloaded_something = false }
end

#process_new_async_value(new_value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rails_development_boost/async.rb', line 46

def process_new_async_value(new_value)
  if new_value
    if !Async.usable?
      msg = 'Unable to start rails-dev-boost in an asynchronous mode. '
      if gem_error = Reactor.gem_load_error
        msg << "Please install the missing gem for even faster rails-dev-boost experience:\n#{gem_error}\n" <<
               "If you can't use the suggest gem version please let me know at https://github.com/thedarkone/rails-dev-boost/issues !\n"
      else
        msg << "Are you running on a OS that is 'async-unsupported' by rails-dev-boost? Please open an issue on github: https://github.com/thedarkone/rails-dev-boost/issues !"
      end
      msg << "\nTo get rid of this message disable the rails-dev-boost's async mode by putting the following code " +
             "in a Rails initializer file (these are found in config/initializers directory):\n" +
             "\n\tRailsDevelopmentBoost.async = false if defined?(RailsDevelopmentBoost)\n\n"
      async_warning(msg)
      new_value = false
    elsif in_console?
      async_warning('Warning: using asynchronous mode in Rails console mode might result in surprising behaviour and is not recommended.')
    end
  end
  new_value
end

#synchronizeObject



38
39
40
# File 'lib/rails_development_boost/async.rb', line 38

def synchronize
  MONITOR.synchronize { yield }
end

#usable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rails_development_boost/async.rb', line 42

def usable?
  Reactor.implementation
end