1
0
Fork 0
mirror of https://github.com/mperham/connection_pool synced 2023-03-27 23:22:21 -04:00

Rejigger exceptions, fixes #130

This commit is contained in:
Mike Perham 2020-06-02 13:11:59 -07:00
parent c46a347ca4
commit dd5dac5660
4 changed files with 15 additions and 16 deletions

View file

@ -1,9 +1,9 @@
connection\_pool changelog
---------------------------
# connection_pool Changelog
HEAD
2.2.3
------
- Pool now throws `ConnectionPool::TimeoutError` on timeout. [#130]
- Use monotonic clock present in all modern Rubies [Tero Tasanen, #109]
- Remove code hacks necessary for JRuby 1.7
- Expose wrapped pool from ConnectionPool::Wrapper [Thomas Lecavelier, #113]

View file

@ -1,5 +1,6 @@
require_relative 'connection_pool/version'
require_relative 'connection_pool/timed_stack'
require 'connection_pool/version'
require 'connection_pool/errors'
require 'connection_pool/timed_stack'
# Generic connection pool class for sharing a limited number of objects or network connections
@ -34,9 +35,6 @@ require_relative 'connection_pool/timed_stack'
class ConnectionPool
DEFAULTS = {size: 5, timeout: 5}
class Error < RuntimeError
end
def self.wrap(options, &block)
Wrapper.new(options, &block)
end

View file

@ -0,0 +1,7 @@
require 'timeout'
class ConnectionPool
class Error < RuntimeError; end
class ConnectionPool::PoolShuttingDownError < ConnectionPool::Error; end
class ConnectionPool::TimeoutError < Timeout::Error; end
end

View file

@ -1,10 +1,4 @@
require 'timeout'
##
# Raised when you attempt to retrieve a connection from a pool that has been
# shut down.
class ConnectionPool::PoolShuttingDownError < RuntimeError; end
require 'connection_pool/errors'
##
# The TimedStack manages a pool of homogeneous connections (or any resource
@ -82,7 +76,7 @@ class ConnectionPool::TimedStack
return connection if connection
to_wait = deadline - current_time
raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0
raise ConnectionPool::TimeoutError, "Waited #{timeout} sec" if to_wait <= 0
@resource.wait(@mutex, to_wait)
end
end