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.
- data/README.md +38 -3
- data/VERSION +1 -1
- data/em-net-http.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
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.
|
1
|
+
0.1.3
|
data/em-net-http.gemspec
CHANGED