Class: RubyLLM::Chat::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb

Overview

Represents an active subscription to a callback event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_list, callback, monitor:, tag: nil) ⇒ Subscription

Returns a new instance of Subscription.



20
21
22
23
24
25
26
# File 'lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb', line 20

def initialize(callback_list, callback, monitor:, tag: nil)
  @callback_list = callback_list
  @callback = callback
  @monitor = monitor
  @tag = tag
  @active = true
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



18
19
20
# File 'lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb', line 18

def tag
  @tag
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb', line 38

def active?
  @monitor.synchronize do
    @active && @callback_list.include?(@callback)
  end
end

#inspectObject



44
45
46
# File 'lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb', line 44

def inspect
  "#<#{self.class.name} tag=#{@tag.inspect} active=#{active?}>"
end

#unsubscribeObject

rubocop:disable Naming/PredicateMethod



28
29
30
31
32
33
34
35
36
# File 'lib/swarm_sdk/ruby_llm_patches/chat_callbacks_patch.rb', line 28

def unsubscribe # rubocop:disable Naming/PredicateMethod
  @monitor.synchronize do
    return false unless @active

    @callback_list.delete(@callback)
    @active = false
  end
  true
end