Class: BreakerMachines::AsyncCircuit

Inherits:
Circuit
  • Object
show all
Includes:
Circuit::AsyncStateManagement
Defined in:
lib/breaker_machines/async_circuit.rb

Overview

AsyncCircuit provides a circuit breaker with async-enabled state machine for thread-safe, fiber-safe concurrent operations

Instance Method Summary collapse

Methods included from Circuit::Base

#initialize

Instance Method Details

#call_async(&block) ⇒ Object

Additional async-specific methods



14
15
16
17
18
19
20
# File 'lib/breaker_machines/async_circuit.rb', line 14

def call_async(&block)
  require 'async' unless defined?(::Async)

  Async do
    call(&block)
  end
end

#fire_async(event_name) ⇒ Async::Task

Fire state transition events asynchronously

Parameters:

  • event_name (Symbol)

    The event to fire

Returns:

  • (Async::Task)

    The async task



25
26
27
28
29
# File 'lib/breaker_machines/async_circuit.rb', line 25

def fire_async(event_name)
  require 'async' unless defined?(::Async)

  fire_event_async(event_name)
end

#health_check_asyncObject

Check circuit health asynchronously Useful for monitoring multiple circuits concurrently



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/breaker_machines/async_circuit.rb', line 33

def health_check_async
  require 'async' unless defined?(::Async)

  Async do
    {
      name: @name,
      status: status_name,
      open: open?,
      stats: stats.to_h,
      can_recover: open? && reset_timeout_elapsed?
    }
  end
end