Class: CouchProxy::ReduceProcess
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- CouchProxy::ReduceProcess
- Defined in:
- lib/couchproxy/reducer.rb
Instance Method Summary collapse
-
#initialize(unbind = nil) ⇒ ReduceProcess
constructor
A new instance of ReduceProcess.
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #rereduce(fn, values, callback) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(unbind = nil) ⇒ ReduceProcess
Returns a new instance of ReduceProcess.
26 27 28 |
# File 'lib/couchproxy/reducer.rb', line 26 def initialize(unbind=nil) @unbind, @connected, @callbacks, @deferred = unbind, false, [], [] end |
Instance Method Details
#post_init ⇒ Object
30 31 32 33 34 35 |
# File 'lib/couchproxy/reducer.rb', line 30 def post_init @connected = true @deferred.slice!(0, @deferred.size).each do |fn, values, callback| rereduce(fn, values, callback) end end |
#receive_data(data) ⇒ Object
46 47 48 49 50 |
# File 'lib/couchproxy/reducer.rb', line 46 def receive_data(data) data.split("\n").each do |line| @callbacks.shift.call(JSON.parse(line)) end end |
#rereduce(fn, values, callback) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/couchproxy/reducer.rb', line 37 def rereduce(fn, values, callback) if @connected @callbacks << callback send_data(["rereduce", [fn], values].to_json + "\n") else @deferred << [fn, values, callback] end end |
#unbind ⇒ Object
52 53 54 55 |
# File 'lib/couchproxy/reducer.rb', line 52 def unbind @connected = false @unbind.call if @unbind end |