Class: Riffer::StreamEvents::Interrupt

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/stream_events/interrupt.rb

Overview

Represents an interrupt event during streaming.

Emitted when a callback interrupts the agent loop via throw :riffer_interrupt.

Instance Attribute Summary collapse

Attributes inherited from Base

#role

Instance Method Summary collapse

Constructor Details

#initialize(reason: nil) ⇒ Interrupt

– : (?reason: (String | Symbol)?) -> void



13
14
15
16
# File 'lib/riffer/stream_events/interrupt.rb', line 13

def initialize(reason: nil)
  super(role: :system)
  @reason = reason
end

Instance Attribute Details

#reasonObject (readonly)

The reason provided with the interrupt, if any.



9
10
11
# File 'lib/riffer/stream_events/interrupt.rb', line 9

def reason
  @reason
end

Instance Method Details

#to_hObject

Converts the event to a hash.

– : () -> Hash[Symbol, untyped]



22
23
24
25
26
# File 'lib/riffer/stream_events/interrupt.rb', line 22

def to_h
  h = {role: @role, interrupt: true}
  h[:reason] = @reason if @reason
  h
end