Class: Grumlin::Client::PoolResource

Inherits:
Async::Pool::Resource
  • Object
show all
Defined in:
lib/grumlin/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, client_factory:, concurrency: 1, parent: Async::Task.current) ⇒ PoolResource

Returns a new instance of PoolResource.



12
13
14
15
16
# File 'lib/grumlin/client.rb', line 12

def initialize(url, client_factory:, concurrency: 1, parent: Async::Task.current)
  super(concurrency)
  @client = client_factory.call(url, parent).tap(&:connect)
  @parent = parent
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/grumlin/client.rb', line 5

def client
  @client
end

Class Method Details

.callObject



7
8
9
10
# File 'lib/grumlin/client.rb', line 7

def self.call
  config = Grumlin.config
  new(config.url, client_factory: config.client_factory, concurrency: config.client_concurrency)
end

Instance Method Details

#closeObject



22
23
24
# File 'lib/grumlin/client.rb', line 22

def close
  @client.close
end

#closed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/grumlin/client.rb', line 18

def closed?
  !@client.connected?
end

#reusable?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/grumlin/client.rb', line 36

def reusable?
  !closed?
end

#viable?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/grumlin/client.rb', line 32

def viable?
  !closed?
end

#write(query) ⇒ Object



26
27
28
29
30
# File 'lib/grumlin/client.rb', line 26

def write(query)
  @client.write(query)
ensure
  @count += 1
end