Class: Parse::Agent::MCPSubscriptions::Debouncer Private
- Inherits:
-
Object
- Object
- Parse::Agent::MCPSubscriptions::Debouncer
- Defined in:
- lib/parse/agent/mcp_subscriptions.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Trailing-debounce coalescer for one (session, uri) subscription.
The first event in a quiet period arms a one-shot timer; events that arrive before it fires are coalesced (dropped) so the timer emits a single update. After the emit the coalescer rearms on the next event. This bounds emission to at most one notification per window regardless of event rate.
The timer mechanism is injected (timer:) so tests can drive emission
deterministically instead of sleeping. The default spawns a short-lived
thread per burst (not per event); at most one timer thread is live per
coalescer at a time.
Instance Method Summary collapse
-
#initialize(interval:, timer: nil) { ... } ⇒ Debouncer
constructor
private
A new instance of Debouncer.
-
#trigger ⇒ Object
private
Record an event; arm the timer if not already armed.
Constructor Details
#initialize(interval:, timer: nil) { ... } ⇒ Debouncer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Debouncer.
279 280 281 282 283 284 285 |
# File 'lib/parse/agent/mcp_subscriptions.rb', line 279 def initialize(interval:, timer: nil, &emit) @interval = interval @emit = emit @timer = timer || method(:default_timer) @armed = false @mutex = Mutex.new end |
Instance Method Details
#trigger ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Record an event; arm the timer if not already armed.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/parse/agent/mcp_subscriptions.rb', line 288 def trigger if @interval <= 0 @emit.call return end should_arm = @mutex.synchronize do next false if @armed @armed = true end return unless should_arm @timer.call(@interval) do @mutex.synchronize { @armed = false } @emit.call end end |