em-net-http 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +38 -3
  2. data/VERSION +1 -1
  3. data/em-net-http.gemspec +1 -1
  4. metadata +2 -2
data/README.md CHANGED
@@ -1,3 +1,38 @@
1
- Using the magic of Ruby 1.9's Fibers, we monkeypatch Net::HTTP to use
2
- the faster, nonblocking em-http-request under the hood. Obviously this
3
- will only work from inside the EventMachine event loop.
1
+ Most Ruby web API libraries use <tt>Net::HTTP</tt> (because it's ubiquitous),
2
+ but I want to use them in my non-blocking EventMachine-based applications, and
3
+ I don't want Net::HTTP to block. I therefore wrote this.
4
+
5
+ Using the magic of Ruby 1.9's Fibers, we monkeypatch <tt>Net::HTTP</tt> to use
6
+ the faster, nonblocking <tt>[em-http-request][1]</tt> under the hood. Obviously this
7
+ will only work from inside the [EventMachine][2] event loop, and from within a spawned
8
+ fiber:
9
+
10
+ require 'em-net-http'
11
+
12
+ EM.run do
13
+ Fiber.new do
14
+ Net::HTTP.start('encrypted.google.com', :use_ssl=>true) do |http|
15
+ res = http.get('/search?q=james')
16
+ puts res.body
17
+ end
18
+ EM.stop_event_loop
19
+ end.resume
20
+ end
21
+
22
+ The above will run without blocking your carefully-tuned nonblocking webapp.
23
+
24
+ I have vaguely tested <tt>em-net-http</tt> with <tt>[right_aws][3]</tt>,
25
+ [Weary][4] and the [Tumblr gem][5]. There's no actual unit tests as such; if you're
26
+ feeling smarter than I am, please feel free to contribute some! <tt>:-)</tt>
27
+
28
+ ### Caveat
29
+
30
+ The <tt>Net::HTTP</tt> API is a many-headed hydra -- I haven't patched much of it;
31
+ in fact I've patched <tt>Net::HTTP#request</tt>, and that's it. Your mileage may
32
+ therefore vary. Please feed me patches, pull requests and bug reports!
33
+
34
+ [1]: http://github.com/igrigorik/em-http-request
35
+ [2]: http://rubyeventmachine.com/
36
+ [3]: http://rightaws.rubyforge.org/
37
+ [4]: http://github.com/mwunsch/weary
38
+ [5]: http://github.com/mwunsch/tumblr
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{em-net-http}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Fairbairn"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Fairbairn