Class: JsonRpc::Rpc::AsyncResult
- Inherits:
-
Object
- Object
- JsonRpc::Rpc::AsyncResult
- Includes:
- EventMachine::Deferrable
- Defined in:
- lib/json-rpc.rb
Overview
The class RpcDeferrable is useful helps you to build a Json Rpc server into an asynchronous way
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#header ⇒ Object
Returns the value of attribute header.
-
#id ⇒ Object
Returns the value of attribute id.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#each(&blk) ⇒ Object
FIXME thin specific.
- #failed(error_code = :internal_error, msg = nil) ⇒ Object
-
#initialize(env = nil) ⇒ AsyncResult
constructor
A new instance of AsyncResult.
- #reply(obj) ⇒ Object
- #send_header ⇒ Object
Constructor Details
#initialize(env = nil) ⇒ AsyncResult
Returns a new instance of AsyncResult.
134 135 136 137 138 139 |
# File 'lib/json-rpc.rb', line 134 def initialize env = nil @env = env @status = 200 @header = {} @header_sent = false end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
132 133 134 |
# File 'lib/json-rpc.rb', line 132 def env @env end |
#header ⇒ Object
Returns the value of attribute header.
132 133 134 |
# File 'lib/json-rpc.rb', line 132 def header @header end |
#id ⇒ Object
Returns the value of attribute id.
132 133 134 |
# File 'lib/json-rpc.rb', line 132 def id @id end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
131 132 133 |
# File 'lib/json-rpc.rb', line 131 def response @response end |
#status ⇒ Object
Returns the value of attribute status.
132 133 134 |
# File 'lib/json-rpc.rb', line 132 def status @status end |
Instance Method Details
#each(&blk) ⇒ Object
FIXME thin specific
161 162 163 |
# File 'lib/json-rpc.rb', line 161 def each &blk @callback = blk end |
#failed(error_code = :internal_error, msg = nil) ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/json-rpc.rb', line 152 def failed error_code = :internal_error, msg = nil e = Rpc::error(error_code, id, msg) @status = e.status send_header @callback.call(e.result) succeed end |
#reply(obj) ⇒ Object
147 148 149 150 |
# File 'lib/json-rpc.rb', line 147 def reply obj send_header unless @callback @callback.call(Rpc::forge_response(obj, @id)) end |
#send_header ⇒ Object
141 142 143 144 145 |
# File 'lib/json-rpc.rb', line 141 def send_header raise "You should pass env to AsyncResult.new()" unless @env @env['async.callback'].call([@status, @header, self]) unless @header_sent @header_sent = true end |