diff --git a/README.md b/README.md index c614d7b..2f3d12b 100644 --- a/README.md +++ b/README.md @@ -110,8 +110,8 @@ These values can be configured as follows (in seconds): ``` ruby Fetch.configure do |config| - config.connection_max_idle_time = 10 # default - config.keep_alive_timeout = 2 # default + config.max_idle_time = 10 # default + config.keep_alive_timeout = 2 # default end ``` diff --git a/lib/fetch.rb b/lib/fetch.rb index 9153f5b..ef625ef 100644 --- a/lib/fetch.rb +++ b/lib/fetch.rb @@ -10,7 +10,7 @@ def self.configure(&block) end configure do |config| - config.connection_max_idle_time = 10 - config.keep_alive_timeout = 2 + config.max_idle_time = 10 + config.keep_alive_timeout = 2 end end diff --git a/lib/fetch/config.rb b/lib/fetch/config.rb index 46cfef3..a301c5f 100644 --- a/lib/fetch/config.rb +++ b/lib/fetch/config.rb @@ -1,3 +1,3 @@ module Fetch - Config = Struct.new(:connection_max_idle_time, :keep_alive_timeout) + Config = Struct.new(:max_idle_time, :keep_alive_timeout) end diff --git a/lib/fetch/connection_pool.rb b/lib/fetch/connection_pool.rb index 91c45ce..7ead1b0 100644 --- a/lib/fetch/connection_pool.rb +++ b/lib/fetch/connection_pool.rb @@ -72,7 +72,7 @@ def sweep @connections.each do |origin, entry| next if entry.in_use - if entry.last_used + Fetch.config.connection_max_idle_time < Time.now + if entry.last_used + Fetch.config.max_idle_time < Time.now entry.connection.finish @connections.delete origin diff --git a/sig/fetch/config.rbs b/sig/fetch/config.rbs index 56e16c1..184a0fa 100644 --- a/sig/fetch/config.rbs +++ b/sig/fetch/config.rbs @@ -1,6 +1,6 @@ module Fetch class Config - attr_accessor connection_max_idle_time: Integer + attr_accessor max_idle_time: Integer attr_accessor keep_alive_timeout: Integer end end diff --git a/spec/fetch/connection_pool_spec.rb b/spec/fetch/connection_pool_spec.rb index 4ccd047..8ffe7e5 100644 --- a/spec/fetch/connection_pool_spec.rb +++ b/spec/fetch/connection_pool_spec.rb @@ -8,7 +8,7 @@ example 'reusing connections' do pool = Fetch::ConnectionPool.new - Fetch.config.with connection_max_idle_time: 10 do + Fetch.config.with max_idle_time: 10 do conn1 = pool.with_connection(uri, &:itself) conn2 = pool.with_connection(uri, &:itself) @@ -19,7 +19,7 @@ example 'closing idle connections' do pool = Fetch::ConnectionPool.new - Fetch.config.with connection_max_idle_time: 1 do + Fetch.config.with max_idle_time: 1 do conn1 = pool.with_connection(uri, &:itself) sleep 2 conn2 = pool.with_connection(uri, &:itself)