Skip to content

Commit

Permalink
Rejigger exceptions, fixes #130
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Jun 2, 2020
1 parent c46a347 commit dd5dac5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Changes.md
@@ -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]
Expand Down
8 changes: 3 additions & 5 deletions lib/connection_pool.rb
@@ -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
Expand Down Expand Up @@ -34,9 +35,6 @@
class ConnectionPool
DEFAULTS = {size: 5, timeout: 5}

class Error < RuntimeError
end

def self.wrap(options, &block)
Wrapper.new(options, &block)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/connection_pool/errors.rb
@@ -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
10 changes: 2 additions & 8 deletions lib/connection_pool/timed_stack.rb
@@ -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
Expand Down Expand Up @@ -82,7 +76,7 @@ def pop(timeout = 0.5, options = {})
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
Expand Down

0 comments on commit dd5dac5

Please sign in to comment.