Class: MlDsa::Config
- Inherits:
-
Object
- Object
- MlDsa::Config
- Defined in:
- lib/ml_dsa/config.rb
Overview
Thread-safe configuration holder for instrumentation subscribers and pluggable RNG. Each Ractor or test context can have its own Config instance.
Instance Attribute Summary collapse
-
#random_source ⇒ Proc?
The current random source, or nil for OS CSPRNG.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #notify(operation, param_set, count, duration_ns) ⇒ Object
-
#subscribe {|Hash| ... } ⇒ Proc
Subscribe to instrumentation events.
-
#unsubscribe(subscriber) ⇒ Proc?
Remove a previously registered subscriber.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 |
# File 'lib/ml_dsa/config.rb', line 13 def initialize @subscribers = [] @mutex = Mutex.new @random_source = nil end |
Instance Attribute Details
#random_source ⇒ Proc?
Returns the current random source, or nil for OS CSPRNG.
38 39 40 |
# File 'lib/ml_dsa/config.rb', line 38 def random_source @random_source end |
Instance Method Details
#notify(operation, param_set, count, duration_ns) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ml_dsa/config.rb', line 52 def notify(operation, param_set, count, duration_ns) # In non-main Ractors, skip instrumentation to avoid isolation errors if defined?(Ractor) && Ractor.respond_to?(:main?) && !Ractor.main? return nil end subs = @mutex.synchronize { @subscribers.dup } return if subs.empty? event = { operation: operation, param_set: param_set, count: count, duration_ns: duration_ns }.freeze subs.each { |s| s.call(event) } nil end |
#subscribe {|Hash| ... } ⇒ Proc
Subscribe to instrumentation events. The block receives a frozen Hash
with keys :operation, :param_set, :count, and :duration_ns.
24 25 26 27 28 |
# File 'lib/ml_dsa/config.rb', line 24 def subscribe(&block) raise ArgumentError, "subscribe requires a block" unless block @mutex.synchronize { @subscribers << block } block end |
#unsubscribe(subscriber) ⇒ Proc?
Remove a previously registered subscriber.
33 34 35 |
# File 'lib/ml_dsa/config.rb', line 33 def unsubscribe(subscriber) @mutex.synchronize { @subscribers.delete(subscriber) } end |