Class: RubyLLM::MCP::Native::Transports::Support::RateLimiter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/mcp/native/transports/support/rate_limiter.rb

Instance Method Summary collapse

Constructor Details

#initialize(limit: 10, interval: 1000) ⇒ RateLimiter

Returns a new instance of RateLimiter.



9
10
11
12
13
14
# File 'lib/ruby_llm/mcp/native/transports/support/rate_limiter.rb', line 9

def initialize(limit: 10, interval: 1000)
  @limit = limit
  @interval = interval
  @timestamps = []
  @mutex = Mutex.new
end

Instance Method Details

#addObject



25
26
27
28
29
30
31
32
# File 'lib/ruby_llm/mcp/native/transports/support/rate_limiter.rb', line 25

def add
  now = current_time

  @mutex.synchronize do
    purge_old(now)
    @timestamps << now
  end
end

#exceeded?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/mcp/native/transports/support/rate_limiter.rb', line 16

def exceeded?
  now = current_time

  @mutex.synchronize do
    purge_old(now)
    @timestamps.size >= @limit
  end
end