Class: Swift::Pool
- Inherits:
-
Object
- Object
- Swift::Pool
- Defined in:
- lib/swift/pool.rb
Defined Under Namespace
Modules: Handler
Instance Method Summary collapse
- #attach(c) ⇒ Object
- #attached?(fd) ⇒ Boolean
- #detach(c) ⇒ Object
- #execute(sql, *bind, &callback) ⇒ Object
-
#initialize(size, options) ⇒ Pool
constructor
A new instance of Pool.
- #run(&block) ⇒ Object
Constructor Details
Instance Method Details
#attach(c) ⇒ Object
37 38 39 |
# File 'lib/swift/pool.rb', line 37 def attach c @pending[c] = true end |
#attached?(fd) ⇒ Boolean
49 50 51 |
# File 'lib/swift/pool.rb', line 49 def attached? fd @pending.keys.select{|c| c.socket == fd}.length > 0 end |
#detach(c) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/swift/pool.rb', line 41 def detach c @pending.delete(c) unless @queue.empty? sql, bind, callback = @queue.shift execute(sql, *bind, &callback) end end |
#execute(sql, *bind, &callback) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/swift/pool.rb', line 53 def execute sql, *bind, &callback request = @pool.execute sql, *bind, &callback # TODO EM throws exceptions in C++ land which are not trapped in the extension. # This is somehow causing everything to unravel and result in a segfault which # I cannot track down. I'll buy a beer for someone who can get this fixed :) # Oh, here it throws an exception if we try to attach same fd twice. if request && !attached?(request.socket) EM.watch(request.socket, Handler, request, self) do |c| attach c c.notify_writable = @writable c.notify_readable = true end else @queue << [ sql, bind, callback ] end end |
#run(&block) ⇒ Object
70 71 72 |
# File 'lib/swift/pool.rb', line 70 def run &block EM.run{ yield self } end |