Class: Asynchronic::GarbageCollector
- Inherits:
-
Object
- Object
- Asynchronic::GarbageCollector
- Defined in:
- lib/asynchronic/garbage_collector.rb
Instance Method Summary collapse
- #add_condition(name, &block) ⇒ Object
- #conditions_names ⇒ Object
-
#initialize(environment, timeout) ⇒ GarbageCollector
constructor
A new instance of GarbageCollector.
- #remove_condition(name) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(environment, timeout) ⇒ GarbageCollector
Returns a new instance of GarbageCollector.
4 5 6 7 8 9 |
# File 'lib/asynchronic/garbage_collector.rb', line 4 def initialize(environment, timeout) @environment = environment @timeout = timeout @running = false @conditions = {} end |
Instance Method Details
#add_condition(name, &block) ⇒ Object
42 43 44 |
# File 'lib/asynchronic/garbage_collector.rb', line 42 def add_condition(name, &block) conditions[name] = block end |
#conditions_names ⇒ Object
50 51 52 |
# File 'lib/asynchronic/garbage_collector.rb', line 50 def conditions_names conditions.keys end |
#remove_condition(name) ⇒ Object
46 47 48 |
# File 'lib/asynchronic/garbage_collector.rb', line 46 def remove_condition(name) conditions.delete name end |
#start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/asynchronic/garbage_collector.rb', line 11 def start Asynchronic.logger.info('Asynchronic') { 'Starting GC' } Signal.trap('QUIT') { stop } @running = true while @running processes = environment.processes processes.each(&:abort_if_dead) conditions.each do |name, condition| Asynchronic.logger.info('Asynchronic') { "Running GC - #{name}" } begin processes.select(&condition).each(&:destroy) rescue => ex = "#{ex.class}: #{ex.}\n#{ex.backtrace.join("\n")}" Asynchronic.logger.error('Asynchronic') { } end end wait end end |
#stop ⇒ Object
37 38 39 40 |
# File 'lib/asynchronic/garbage_collector.rb', line 37 def stop Asynchronic.logger.info('Asynchronic') { 'Stopping GC' } @running = false end |