em_mysql2_connection_pool 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ require 'mysql2'
2
+ require 'mysql2/em'
3
+
4
+ class EmMysql2ConnectionPool
5
+ def initialize(conf)
6
+ @pool_size = conf[:size] || 10
7
+ @query_queue = EM::Queue.new
8
+ start_queue conf
9
+ end
10
+
11
+ def worker
12
+ proc{ |connection|
13
+ @query_queue.pop do |query|
14
+ connection.query(query[:sql], query[:opts]).callback do |result|
15
+ query[:callback].call result if query[:callback]
16
+ worker.call connection
17
+ end
18
+ end
19
+ }
20
+ end
21
+
22
+ def start_queue(conf)
23
+ @pool_size.times do
24
+ worker.call Mysql2::EM::Client.new conf
25
+ end
26
+ end
27
+
28
+ def query(sql, opts={}, &block)
29
+ @query_queue.push :sql => sql, :opts => opts, :callback => block
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module EmMysql2ConnectionPool
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em_mysql2_connection_pool
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Niko Dittmann
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-02 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: the most simple, one trick, ultra thin connection pool for MySQL2 usage in a Eventmachine reactor loop.
22
+ email: mail+git@niko-dittmann.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/em_mysql2_connection_pool/version.rb
31
+ - lib/em_mysql2_connection_pool.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/niko/em_mysql2_connection_pool
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: em_mysql2_connection_pool
60
+ rubygems_version: 1.3.7
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: a simple connection pool for Mysql2::EM connections
64
+ test_files: []
65
+