sucker 2.0.0.pre.3 → 2.0.0.pre.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -83,7 +83,7 @@ adapter.socket_local.host = '10.0.0.2'
83
83
  Evented Requests
84
84
  ----------------
85
85
 
86
- I am including a simple synchrony driver in the 2.0 major version release.
86
+ I am including a EM:Synchrony patch in the 2.0 release.
87
87
 
88
88
  ```ruby
89
89
  require 'sucker/synchrony'
@@ -94,6 +94,8 @@ EM.synchrony do
94
94
  # do something with the response
95
95
  EM.stop
96
96
  end
97
+
98
+ For more meaningful examples, read [these examples](http://relishapp.com/papercavalier/sucker/evented-requests).
97
99
  ```
98
100
 
99
101
  Stubbing Tests
@@ -63,7 +63,7 @@ module Sucker
63
63
  parameters.merge!(hash)
64
64
  end
65
65
 
66
- # Performs a request and returns a response object.
66
+ # Performs a request and returns a response.
67
67
  #
68
68
  # response = request.get
69
69
  #
@@ -3,11 +3,20 @@ require 'em-synchrony'
3
3
  require 'em-synchrony/em-http'
4
4
 
5
5
  module Sucker
6
+ # Below, we minimally patch Request and Response to make them fiber-aware.
6
7
  class Request
7
8
  def adapter
8
9
  @adapter ||= EM::HttpRequest
9
10
  end
10
11
 
12
+ # Performs an evented request and yields a response to provided block.
13
+ def aget(&block)
14
+ http = EM::HttpRequest.new(url).aget
15
+ http.callback { block.call(Response.new(http)) }
16
+ http.errback { block.call(Response.new(http)) }
17
+ end
18
+
19
+ # Performs an evented request and returns a response.
11
20
  def get
12
21
  http = EM::HttpRequest.new(url).get
13
22
  Response.new(http)
@@ -1,3 +1,3 @@
1
1
  module Sucker
2
- VERSION = '2.0.0.pre.3'
2
+ VERSION = '2.0.0.pre.4'
3
3
  end
@@ -18,12 +18,27 @@ module Sucker
18
18
  request.adapter.should eql ::EM::HttpRequest
19
19
  end
20
20
 
21
+ describe "#aget" do
22
+ it "yields a response" do
23
+ response = nil
24
+ EM.synchrony do
25
+ request.aget { |resp| response = resp }
26
+ EM.stop
27
+ end
28
+
29
+ response.should be_a Response
30
+ end
31
+ end
32
+
21
33
  describe "#get" do
22
34
  it "returns a response" do
35
+ response = nil
23
36
  EM.synchrony do
24
37
  response = request.get
25
38
  EM.stop
26
39
  end
40
+
41
+ response.should be_a Response
27
42
  end
28
43
  end
29
44
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - pre
10
- - 3
11
- version: 2.0.0.pre.3
10
+ - 4
11
+ version: 2.0.0.pre.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Paper Cavalier
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-20 00:00:00 +01:00
19
+ date: 2011-06-21 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency