Class: Fractor::MainLoopHandler3

Inherits:
MainLoopHandler show all
Defined in:
lib/fractor/main_loop_handler3.rb

Overview

Ruby 3.x specific implementation of MainLoopHandler. Uses Ractor.yield for worker communication.

Instance Method Summary collapse

Methods inherited from MainLoopHandler

#cleanup_ractors_map, create, #initialize, #initiate_shutdown

Constructor Details

This class inherits a constructor from Fractor::MainLoopHandler

Instance Method Details

#run_loopObject

Run the main event loop for Ruby 3.x.



10
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
36
37
38
39
# File 'lib/fractor/main_loop_handler3.rb', line 10

def run_loop
  loop do
    processed_count = get_processed_count

    # Check loop termination condition
    break unless should_continue_running?(processed_count)

    log_processing_status(processed_count)

    active_ractors = get_active_ractors

    # Check for new work from callbacks if in continuous mode
    process_work_callbacks if continuous_mode? && @supervisor.callback_registry.has_work_callbacks?

    # Handle edge cases - break if edge case handler indicates we should
    next if handle_edge_cases(active_ractors, processed_count)

    # Wait for next message from any active ractor
    ready_ractor_obj, message = select_from_ractors(active_ractors)
    next unless ready_ractor_obj && message

    # Process the received message
    process_message(ready_ractor_obj, message)
  end

  puts "Main loop finished." if @debug

  # Clean up ractors map after batch mode completion
  cleanup_ractors_map unless continuous_mode?
end