Class: GrpcKit::RpcDispatcher::AutoTrimmer

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_kit/rpc_dispatcher/auto_trimmer.rb

Instance Method Summary collapse

Constructor Details

#initialize(pool, interval: 30) ⇒ AutoTrimmer

Returns a new instance of AutoTrimmer.



6
7
8
9
10
# File 'lib/grpc_kit/rpc_dispatcher/auto_trimmer.rb', line 6

def initialize(pool, interval: 30)
  @pool = pool
  @interval = interval
  @running = false
end

Instance Method Details

#start!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/grpc_kit/rpc_dispatcher/auto_trimmer.rb', line 12

def start!
  @running = true
  @thread = Thread.new do
    loop do
      unless @running
        GrpcKit.logger.debug('Stop AutoTrimer')
        break
      end
      @pool.trim
      sleep @interval
    end
  end
end

#stopObject



26
27
28
29
# File 'lib/grpc_kit/rpc_dispatcher/auto_trimmer.rb', line 26

def stop
  @running = false
  @thread.wakeup
end