Class: Orchestrator::DependencyManager
- Inherits:
-
Object
- Object
- Orchestrator::DependencyManager
- Includes:
- Singleton
- Defined in:
- lib/orchestrator/dependency_manager.rb
Instance Method Summary collapse
- #force_load(file) ⇒ Object
-
#initialize ⇒ DependencyManager
constructor
A new instance of DependencyManager.
- #load(dependency, force = false) ⇒ Object
Constructor Details
#initialize ⇒ DependencyManager
Returns a new instance of DependencyManager.
10 11 12 13 14 15 16 17 |
# File 'lib/orchestrator/dependency_manager.rb', line 10 def initialize @load_mutex = Mutex.new @dependencies = ThreadSafe::Cache.new @loop = ::Libuv::Loop.default @loop.next_tick do @logger = ::Orchestrator::Control.instance.logger end end |
Instance Method Details
#force_load(file) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/orchestrator/dependency_manager.rb', line 39 def force_load(file) defer = @loop.defer if File.exists?(file) begin @load_mutex.synchronize { load file } defer.resolve(file) rescue Exception => e defer.reject(e) print_error(e, 'force load failed') end else defer.reject(Error::FileNotFound.new("could not find '#{file}'")) end defer.promise end |
#load(dependency, force = false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/orchestrator/dependency_manager.rb', line 20 def load(dependency, force = false) defer = @loop.defer classname = dependency.class_name class_lookup = classname.to_sym class_object = @dependencies[class_lookup] if class_object && force == false defer.resolve(class_object) else # We need to ensure only one file loads at a time @load_mutex.synchronize { perform_load(dependency, defer, classname, class_lookup, force) } end defer.promise end |