Parent

Class Index [+]

Quicksearch

MessagePack::RPC::MultiFuture

MultiFuture bunldes up multiple Future objects.

Attributes

all[R]

Gets all registered Future objects.

not_joined[R]

Gets Future objects which are not joined yet.

joined[R]

Gets Future objects which are already joined.

error[R]

Gets Future objects which are joined as error.

success[R]

Gets Future objects which are joined as success.

Public Class Methods

new() click to toggle source
    # File lib/msgpack/rpc/multi_future.rb, line 24
24:         def initialize
25:                 @all = []
26: 
27:                 @not_joined = []
28:                 @joined = []
29:                 @error = []
30:                 @success = []
31: 
32:                 @on_all = nil
33:                 @on_error = nil
34:                 @on_success = nil
35:                 @on_num = {}  # {num => callback}
36:         end

Public Instance Methods

add(future) click to toggle source

Registeres new Future object. Returns self.

    # File lib/msgpack/rpc/multi_future.rb, line 76
76:         def add(future)
77:                 future.attach_callback(&method(:callback))
78:                 @all << future
79:                 @not_joined << future
80:                 self
81:         end
clear() click to toggle source

Clears all Future objects and all callback methods.

    # File lib/msgpack/rpc/multi_future.rb, line 54
54:         def clear
55:                 @all = []
56: 
57:                 @not_joined = []
58:                 @joined = []
59:                 @error = []
60:                 @success = []
61: 
62:                 clear_callback
63:         end
clear_callback() click to toggle source

Clears all callback methods registered by on_xxx methods.

    # File lib/msgpack/rpc/multi_future.rb, line 66
66:         def clear_callback
67:                 @on_all = nil
68:                 @on_error = nil
69:                 @on_success = nil
70:                 @on_num = {}
71:                 self
72:         end
join_all() click to toggle source

Waits until all Future objects join.

     # File lib/msgpack/rpc/multi_future.rb, line 116
116:         def join_all
117:                 @not_joined.each {|future|
118:                         future.join
119:                 }
120:                 @all
121:         end
join_error() click to toggle source

Waits until at least one Future object joins as error. Returns the joined Future object or nil.

     # File lib/msgpack/rpc/multi_future.rb, line 137
137:         def join_error
138:                 until @not_joined.empty?
139:                         unless @error.empty?
140:                                 break
141:                         end
142:                         @not_joined.first.loop.run_once
143:                 end
144:                 @error.last
145:         end
join_num(n) click to toggle source

Waits until specified number of Future objects join. Returns the joined Future objects or nil.

     # File lib/msgpack/rpc/multi_future.rb, line 149
149:         def join_num(n)
150:                 until @not_joined.empty?
151:                         unless @joined.size >= n
152:                                 return @joined
153:                         end
154:                         @not_joined.first.loop.run_once
155:                 end
156:                 nil
157:         end
join_success() click to toggle source

Waits until at least one Future object joins as success. Returns the joined Future object or nil.

     # File lib/msgpack/rpc/multi_future.rb, line 125
125:         def join_success
126:                 until @not_joined.empty?
127:                         unless @success.empty?
128:                                 break
129:                         end
130:                         @not_joined.first.loop.run_once
131:                 end
132:                 @success.last
133:         end
on_all(&block) click to toggle source

Attaches a callback method that is called when all Future objects are joined. Returns self.

    # File lib/msgpack/rpc/multi_future.rb, line 86
86:         def on_all(&block)
87:                 @on_all = block
88:                 self
89:         end
on_error(&block) click to toggle source

Attaches a callback method that is called when Future objects are joined as error. Returns self.

     # File lib/msgpack/rpc/multi_future.rb, line 102
102:         def on_error(&block)
103:                 @on_error = block
104:                 self
105:         end
on_num(n, &block) click to toggle source

Attaches a callback method that is called when specified number of Future objects are joined. Returns self.

     # File lib/msgpack/rpc/multi_future.rb, line 110
110:         def on_num(n, &block)
111:                 @on_num[n.to_i] = block
112:                 self
113:         end
on_success(&block) click to toggle source

Attaches a callback method that is called when Future objects are joined as success. Returns self.

    # File lib/msgpack/rpc/multi_future.rb, line 94
94:         def on_success(&block)
95:                 @on_success = block
96:                 self
97:         end

Private Instance Methods

callback(future) click to toggle source
     # File lib/msgpack/rpc/multi_future.rb, line 161
161:         def callback(future)
162:                 if @not_joined.delete(future)
163:                         @joined << future
164: 
165:                         if future.error == nil
166:                                 @success << future
167:                                 if @on_success
168:                                         @on_success.call(future) rescue nil
169:                                 end
170:                         else
171:                                 @error << future
172:                                 if @on_error
173:                                         @on_error.call(future) rescue nil
174:                                 end
175:                         end
176: 
177:                         if callback = @on_num[@joined.size]
178:                                 callback.call(@joined) rescue nil
179:                         end
180: 
181:                         if @on_all && @not_joined.empty?
182:                                 @on_all.call(@all) rescue nil
183:                         end
184:                 end
185:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.