simple-future 1.0.0.pre1 → 1.0.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +175 -0
- data/Rakefile +27 -0
- data/doc/SimpleFuture/ChildError.html +411 -0
- data/doc/SimpleFuture/Error.html +140 -0
- data/doc/SimpleFuture/ResultTypeError.html +147 -0
- data/doc/SimpleFuture.html +998 -0
- data/doc/_index.html +152 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +499 -0
- data/doc/file.README.html +255 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +255 -0
- data/doc/js/app.js +248 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +147 -0
- data/doc/top-level-namespace.html +110 -0
- data/simple-future.gemspec +31 -0
- data/spec/simple-future_spec.rb +180 -0
- data/spec/spec_helper.rb +6 -0
- metadata +25 -1
@@ -0,0 +1,998 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: SimpleFuture
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.12
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "SimpleFuture";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index (S)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">SimpleFuture</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: SimpleFuture
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName">Object</span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">SimpleFuture</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<dl>
|
96
|
+
<dt>Defined in:</dt>
|
97
|
+
<dd>lib/simple-future.rb</dd>
|
98
|
+
</dl>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<h2>Overview</h2><div class="docstring">
|
103
|
+
<div class="discussion">
|
104
|
+
|
105
|
+
<p>A container holding the (eventual) result of a forked child process once
|
106
|
+
that process finishes. The child process executes the code block that must
|
107
|
+
be passed to the constructor:</p>
|
108
|
+
|
109
|
+
<pre class="code ruby"><code class="ruby"> sf = SimpleFuture.new { do_slow_thing }
|
110
|
+
... do stuff ...
|
111
|
+
use(sf.value)</code></pre>
|
112
|
+
|
113
|
+
<p>The code block <strong>must</strong> return a value that can be encoded by
|
114
|
+
<code>Marshal</code> and <strong>must not</strong> exit prematurely.</p>
|
115
|
+
|
116
|
+
<p>Exceptions thrown inside the block will trigger a
|
117
|
+
<code>SimpleFuture::ChildError</code> in the parent process but that
|
118
|
+
exception will contain the original in its <code>cause</code> field.</p>
|
119
|
+
|
120
|
+
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
<div class="tags">
|
124
|
+
|
125
|
+
|
126
|
+
</div><h2>Defined Under Namespace</h2>
|
127
|
+
<p class="children">
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="SimpleFuture/ChildError.html" title="SimpleFuture::ChildError (class)">ChildError</a></span>, <span class='object_link'><a href="SimpleFuture/Error.html" title="SimpleFuture::Error (class)">Error</a></span>, <span class='object_link'><a href="SimpleFuture/ResultTypeError.html" title="SimpleFuture::ResultTypeError (class)">ResultTypeError</a></span>
|
133
|
+
|
134
|
+
|
135
|
+
</p>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
<h2>
|
145
|
+
Class Method Summary
|
146
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
147
|
+
</h2>
|
148
|
+
|
149
|
+
<ul class="summary">
|
150
|
+
|
151
|
+
<li class="public ">
|
152
|
+
<span class="summary_signature">
|
153
|
+
|
154
|
+
<a href="#all_done%3F-class_method" title="all_done? (class method)">.<strong>all_done?</strong> ⇒ Boolean </a>
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
</span>
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
<span class="summary_desc"><div class='inline'>
|
169
|
+
<p>Test if all instances created so far have run to completion.</p>
|
170
|
+
</div></span>
|
171
|
+
|
172
|
+
</li>
|
173
|
+
|
174
|
+
|
175
|
+
<li class="public ">
|
176
|
+
<span class="summary_signature">
|
177
|
+
|
178
|
+
<a href="#max_tasks-class_method" title="max_tasks (class method)">.<strong>max_tasks</strong> ⇒ Object </a>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
</span>
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
<span class="summary_desc"><div class='inline'>
|
193
|
+
<p>Return the maximum number of concurrent child processes allowed.</p>
|
194
|
+
</div></span>
|
195
|
+
|
196
|
+
</li>
|
197
|
+
|
198
|
+
|
199
|
+
<li class="public ">
|
200
|
+
<span class="summary_signature">
|
201
|
+
|
202
|
+
<a href="#max_tasks=-class_method" title="max_tasks= (class method)">.<strong>max_tasks=</strong>(value) ⇒ Object </a>
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
</span>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
<span class="summary_desc"><div class='inline'>
|
217
|
+
<p>Set the maximum number of concurrent child processes allowed.</p>
|
218
|
+
</div></span>
|
219
|
+
|
220
|
+
</li>
|
221
|
+
|
222
|
+
|
223
|
+
<li class="public ">
|
224
|
+
<span class="summary_signature">
|
225
|
+
|
226
|
+
<a href="#wait_for_all-class_method" title="wait_for_all (class method)">.<strong>wait_for_all</strong> ⇒ Object </a>
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
</span>
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
<span class="summary_desc"><div class='inline'>
|
241
|
+
<p>Wait until all child processes have run to completion and recover their
|
242
|
+
results.</p>
|
243
|
+
</div></span>
|
244
|
+
|
245
|
+
</li>
|
246
|
+
|
247
|
+
|
248
|
+
</ul>
|
249
|
+
|
250
|
+
<h2>
|
251
|
+
Instance Method Summary
|
252
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
253
|
+
</h2>
|
254
|
+
|
255
|
+
<ul class="summary">
|
256
|
+
|
257
|
+
<li class="public ">
|
258
|
+
<span class="summary_signature">
|
259
|
+
|
260
|
+
<a href="#check_if_ready-instance_method" title="#check_if_ready (instance method)">#<strong>check_if_ready</strong> ⇒ Boolean </a>
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
</span>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
<span class="summary_desc"><div class='inline'>
|
275
|
+
<p>Check if the child process has finished evaluating the block and has a
|
276
|
+
result ready.</p>
|
277
|
+
</div></span>
|
278
|
+
|
279
|
+
</li>
|
280
|
+
|
281
|
+
|
282
|
+
<li class="public ">
|
283
|
+
<span class="summary_signature">
|
284
|
+
|
285
|
+
<a href="#complete%3F-instance_method" title="#complete? (instance method)">#<strong>complete?</strong> ⇒ Boolean </a>
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
</span>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
<span class="summary_desc"><div class='inline'>
|
300
|
+
<p>Test if the child process has finished and its result is available.</p>
|
301
|
+
</div></span>
|
302
|
+
|
303
|
+
</li>
|
304
|
+
|
305
|
+
|
306
|
+
<li class="public ">
|
307
|
+
<span class="summary_signature">
|
308
|
+
|
309
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(&action) ⇒ SimpleFuture </a>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
</span>
|
314
|
+
|
315
|
+
|
316
|
+
<span class="note title constructor">constructor</span>
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
<span class="summary_desc"><div class='inline'>
|
326
|
+
<p>In addition to creating a new <code>SimpleFuture</code>, the constructor
|
327
|
+
creates a child process and evaluates <code>action</code> in it.</p>
|
328
|
+
</div></span>
|
329
|
+
|
330
|
+
</li>
|
331
|
+
|
332
|
+
|
333
|
+
<li class="public ">
|
334
|
+
<span class="summary_signature">
|
335
|
+
|
336
|
+
<a href="#value-instance_method" title="#value (instance method)">#<strong>value</strong> ⇒ Object </a>
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
</span>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
<span class="summary_desc"><div class='inline'>
|
351
|
+
<p>Return the result of the child process, blocking if it is not yet
|
352
|
+
available.</p>
|
353
|
+
</div></span>
|
354
|
+
|
355
|
+
</li>
|
356
|
+
|
357
|
+
|
358
|
+
<li class="public ">
|
359
|
+
<span class="summary_signature">
|
360
|
+
|
361
|
+
<a href="#wait-instance_method" title="#wait (instance method)">#<strong>wait</strong> ⇒ Object </a>
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
</span>
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
<span class="summary_desc"><div class='inline'>
|
376
|
+
<p>Block until the child process finishes, recover its result and clean up the
|
377
|
+
process.</p>
|
378
|
+
</div></span>
|
379
|
+
|
380
|
+
</li>
|
381
|
+
|
382
|
+
|
383
|
+
</ul>
|
384
|
+
|
385
|
+
|
386
|
+
<div id="constructor_details" class="method_details_list">
|
387
|
+
<h2>Constructor Details</h2>
|
388
|
+
|
389
|
+
<div class="method_details first">
|
390
|
+
<h3 class="signature first" id="initialize-instance_method">
|
391
|
+
|
392
|
+
#<strong>initialize</strong>(&action) ⇒ <tt><span class='object_link'><a href="" title="SimpleFuture (class)">SimpleFuture</a></span></tt>
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
</h3><div class="docstring">
|
399
|
+
<div class="discussion">
|
400
|
+
|
401
|
+
<p>In addition to creating a new <code>SimpleFuture</code>, the constructor
|
402
|
+
creates a child process and evaluates <code>action</code> in it. If the
|
403
|
+
maximum number of child processes would be exceeded, it will block until a
|
404
|
+
process finishes.</p>
|
405
|
+
|
406
|
+
|
407
|
+
</div>
|
408
|
+
</div>
|
409
|
+
<div class="tags">
|
410
|
+
|
411
|
+
|
412
|
+
</div><table class="source_code">
|
413
|
+
<tr>
|
414
|
+
<td>
|
415
|
+
<pre class="lines">
|
416
|
+
|
417
|
+
|
418
|
+
88
|
419
|
+
89
|
420
|
+
90
|
421
|
+
91
|
422
|
+
92
|
423
|
+
93
|
424
|
+
94
|
425
|
+
95
|
426
|
+
96
|
427
|
+
97</pre>
|
428
|
+
</td>
|
429
|
+
<td>
|
430
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 88</span>
|
431
|
+
|
432
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_action'>action</span><span class='rparen'>)</span>
|
433
|
+
<span class='ivar'>@readPipe</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
434
|
+
<span class='ivar'>@pid</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
435
|
+
<span class='ivar'>@complete</span> <span class='op'>=</span> <span class='kw'>false</span>
|
436
|
+
<span class='ivar'>@result</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
437
|
+
|
438
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='period'>.</span><span class='id identifier rubyid_all_done?'>all_done?</span> <span class='comment'># Reclaim all completed children
|
439
|
+
</span> <span class='id identifier rubyid_block_until_clear'>block_until_clear</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
440
|
+
<span class='id identifier rubyid_launch'>launch</span><span class='lparen'>(</span><span class='id identifier rubyid_action'>action</span><span class='rparen'>)</span>
|
441
|
+
<span class='kw'>end</span></pre>
|
442
|
+
</td>
|
443
|
+
</tr>
|
444
|
+
</table>
|
445
|
+
</div>
|
446
|
+
|
447
|
+
</div>
|
448
|
+
|
449
|
+
|
450
|
+
<div id="class_method_details" class="method_details_list">
|
451
|
+
<h2>Class Method Details</h2>
|
452
|
+
|
453
|
+
|
454
|
+
<div class="method_details first">
|
455
|
+
<h3 class="signature first" id="all_done?-class_method">
|
456
|
+
|
457
|
+
.<strong>all_done?</strong> ⇒ <tt>Boolean</tt>
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
</h3><div class="docstring">
|
464
|
+
<div class="discussion">
|
465
|
+
|
466
|
+
<p>Test if all instances created so far have run to completion. As a side
|
467
|
+
effect, it will also call <code>wait</code> on instances whose child
|
468
|
+
processes are running but have finished (i.e. their
|
469
|
+
<code>check_if_ready</code> would return true.) This lets you use it as a
|
470
|
+
non-blocking way to clean up the remaining children.</p>
|
471
|
+
|
472
|
+
|
473
|
+
</div>
|
474
|
+
</div>
|
475
|
+
<div class="tags">
|
476
|
+
|
477
|
+
<p class="tag_title">Returns:</p>
|
478
|
+
<ul class="return">
|
479
|
+
|
480
|
+
<li>
|
481
|
+
|
482
|
+
|
483
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
</li>
|
488
|
+
|
489
|
+
</ul>
|
490
|
+
|
491
|
+
</div><table class="source_code">
|
492
|
+
<tr>
|
493
|
+
<td>
|
494
|
+
<pre class="lines">
|
495
|
+
|
496
|
+
|
497
|
+
206
|
498
|
+
207
|
499
|
+
208
|
500
|
+
209</pre>
|
501
|
+
</td>
|
502
|
+
<td>
|
503
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 206</span>
|
504
|
+
|
505
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_all_done?'>all_done?</span>
|
506
|
+
<span class='cvar'>@@in_progress</span><span class='period'>.</span><span class='id identifier rubyid_select!'>select!</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_sp'>sp</span><span class='op'>|</span> <span class='op'>!</span><span class='id identifier rubyid_sp'>sp</span><span class='period'>.</span><span class='id identifier rubyid_check_if_ready'>check_if_ready</span> <span class='rbrace'>}</span>
|
507
|
+
<span class='kw'>return</span> <span class='cvar'>@@in_progress</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>0</span>
|
508
|
+
<span class='kw'>end</span></pre>
|
509
|
+
</td>
|
510
|
+
</tr>
|
511
|
+
</table>
|
512
|
+
</div>
|
513
|
+
|
514
|
+
<div class="method_details ">
|
515
|
+
<h3 class="signature " id="max_tasks-class_method">
|
516
|
+
|
517
|
+
.<strong>max_tasks</strong> ⇒ <tt>Object</tt>
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
</h3><div class="docstring">
|
524
|
+
<div class="discussion">
|
525
|
+
|
526
|
+
<p>Return the maximum number of concurrent child processes allowed.</p>
|
527
|
+
|
528
|
+
|
529
|
+
</div>
|
530
|
+
</div>
|
531
|
+
<div class="tags">
|
532
|
+
|
533
|
+
|
534
|
+
</div><table class="source_code">
|
535
|
+
<tr>
|
536
|
+
<td>
|
537
|
+
<pre class="lines">
|
538
|
+
|
539
|
+
|
540
|
+
190</pre>
|
541
|
+
</td>
|
542
|
+
<td>
|
543
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 190</span>
|
544
|
+
|
545
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_max_tasks'>max_tasks</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='kw'>return</span> <span class='cvar'>@@max_tasks</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
|
546
|
+
</td>
|
547
|
+
</tr>
|
548
|
+
</table>
|
549
|
+
</div>
|
550
|
+
|
551
|
+
<div class="method_details ">
|
552
|
+
<h3 class="signature " id="max_tasks=-class_method">
|
553
|
+
|
554
|
+
.<strong>max_tasks=</strong>(value) ⇒ <tt>Object</tt>
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
</h3><div class="docstring">
|
561
|
+
<div class="discussion">
|
562
|
+
|
563
|
+
<p>Set the maximum number of concurrent child processes allowed. If set to
|
564
|
+
less than 1, it is interpreted as meaning no limit.</p>
|
565
|
+
|
566
|
+
<p>It is initially set to the number of available cores as provided by the
|
567
|
+
<code>Etc</code> module.</p>
|
568
|
+
|
569
|
+
|
570
|
+
</div>
|
571
|
+
</div>
|
572
|
+
<div class="tags">
|
573
|
+
|
574
|
+
|
575
|
+
</div><table class="source_code">
|
576
|
+
<tr>
|
577
|
+
<td>
|
578
|
+
<pre class="lines">
|
579
|
+
|
580
|
+
|
581
|
+
197
|
582
|
+
198
|
583
|
+
199</pre>
|
584
|
+
</td>
|
585
|
+
<td>
|
586
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 197</span>
|
587
|
+
|
588
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_max_tasks='>max_tasks=</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
|
589
|
+
<span class='cvar'>@@max_tasks</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
|
590
|
+
<span class='kw'>end</span></pre>
|
591
|
+
</td>
|
592
|
+
</tr>
|
593
|
+
</table>
|
594
|
+
</div>
|
595
|
+
|
596
|
+
<div class="method_details ">
|
597
|
+
<h3 class="signature " id="wait_for_all-class_method">
|
598
|
+
|
599
|
+
.<strong>wait_for_all</strong> ⇒ <tt>Object</tt>
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
</h3><div class="docstring">
|
606
|
+
<div class="discussion">
|
607
|
+
|
608
|
+
<p>Wait until all child processes have run to completion and recover their
|
609
|
+
results. Programs should call this before exiting if there is a chance that
|
610
|
+
an instance was created without having <code>wait</code> called on it.</p>
|
611
|
+
|
612
|
+
|
613
|
+
</div>
|
614
|
+
</div>
|
615
|
+
<div class="tags">
|
616
|
+
|
617
|
+
|
618
|
+
</div><table class="source_code">
|
619
|
+
<tr>
|
620
|
+
<td>
|
621
|
+
<pre class="lines">
|
622
|
+
|
623
|
+
|
624
|
+
215
|
625
|
+
216
|
626
|
+
217
|
627
|
+
218
|
628
|
+
219</pre>
|
629
|
+
</td>
|
630
|
+
<td>
|
631
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 215</span>
|
632
|
+
|
633
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_wait_for_all'>wait_for_all</span>
|
634
|
+
<span class='cvar'>@@in_progress</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_sp'>sp</span><span class='op'>|</span> <span class='id identifier rubyid_sp'>sp</span><span class='period'>.</span><span class='id identifier rubyid_wait'>wait</span><span class='rbrace'>}</span>
|
635
|
+
<span class='cvar'>@@in_progress</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
636
|
+
<span class='kw'>return</span>
|
637
|
+
<span class='kw'>end</span></pre>
|
638
|
+
</td>
|
639
|
+
</tr>
|
640
|
+
</table>
|
641
|
+
</div>
|
642
|
+
|
643
|
+
</div>
|
644
|
+
|
645
|
+
<div id="instance_method_details" class="method_details_list">
|
646
|
+
<h2>Instance Method Details</h2>
|
647
|
+
|
648
|
+
|
649
|
+
<div class="method_details first">
|
650
|
+
<h3 class="signature first" id="check_if_ready-instance_method">
|
651
|
+
|
652
|
+
#<strong>check_if_ready</strong> ⇒ <tt>Boolean</tt>
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
|
658
|
+
</h3><div class="docstring">
|
659
|
+
<div class="discussion">
|
660
|
+
|
661
|
+
<p>Check if the child process has finished evaluating the block and has a
|
662
|
+
result ready. If <code>check_if_ready</code> returns <code>true</code>,
|
663
|
+
<code>wait</code> will not block when called.</p>
|
664
|
+
|
665
|
+
<p>Note: <code>check_if_ready</code> tests if there's data on the pipe to
|
666
|
+
the child process to see if it has finished. A sufficiently evil child
|
667
|
+
block might be able to cause a true result while still blocking
|
668
|
+
<code>wait</code>.</p>
|
669
|
+
|
670
|
+
<p>Don't do that.</p>
|
671
|
+
|
672
|
+
|
673
|
+
</div>
|
674
|
+
</div>
|
675
|
+
<div class="tags">
|
676
|
+
|
677
|
+
<p class="tag_title">Returns:</p>
|
678
|
+
<ul class="return">
|
679
|
+
|
680
|
+
<li>
|
681
|
+
|
682
|
+
|
683
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
684
|
+
|
685
|
+
|
686
|
+
|
687
|
+
</li>
|
688
|
+
|
689
|
+
</ul>
|
690
|
+
|
691
|
+
</div><table class="source_code">
|
692
|
+
<tr>
|
693
|
+
<td>
|
694
|
+
<pre class="lines">
|
695
|
+
|
696
|
+
|
697
|
+
181
|
698
|
+
182
|
699
|
+
183
|
700
|
+
184
|
701
|
+
185
|
702
|
+
186</pre>
|
703
|
+
</td>
|
704
|
+
<td>
|
705
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 181</span>
|
706
|
+
|
707
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_check_if_ready'>check_if_ready</span>
|
708
|
+
<span class='kw'>return</span> <span class='kw'>true</span> <span class='kw'>if</span> <span class='id identifier rubyid_complete?'>complete?</span>
|
709
|
+
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='ivar'>@readPipe</span><span class='period'>.</span><span class='id identifier rubyid_ready?'>ready?</span>
|
710
|
+
<span class='id identifier rubyid_wait'>wait</span>
|
711
|
+
<span class='kw'>return</span> <span class='kw'>true</span>
|
712
|
+
<span class='kw'>end</span></pre>
|
713
|
+
</td>
|
714
|
+
</tr>
|
715
|
+
</table>
|
716
|
+
</div>
|
717
|
+
|
718
|
+
<div class="method_details ">
|
719
|
+
<h3 class="signature " id="complete?-instance_method">
|
720
|
+
|
721
|
+
#<strong>complete?</strong> ⇒ <tt>Boolean</tt>
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
|
726
|
+
|
727
|
+
</h3><div class="docstring">
|
728
|
+
<div class="discussion">
|
729
|
+
|
730
|
+
<p>Test if the child process has finished and its result is available.</p>
|
731
|
+
|
732
|
+
<p>Note that this will only be true after a call to <code>wait</code> (i.e.
|
733
|
+
the child process finished <strong>and</strong> its result has been
|
734
|
+
retrieved.) If you want to see if the result is (probably) available, use
|
735
|
+
<code>check_if_ready</code>.</p>
|
736
|
+
|
737
|
+
|
738
|
+
</div>
|
739
|
+
</div>
|
740
|
+
<div class="tags">
|
741
|
+
|
742
|
+
<p class="tag_title">Returns:</p>
|
743
|
+
<ul class="return">
|
744
|
+
|
745
|
+
<li>
|
746
|
+
|
747
|
+
|
748
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
749
|
+
|
750
|
+
|
751
|
+
|
752
|
+
</li>
|
753
|
+
|
754
|
+
</ul>
|
755
|
+
|
756
|
+
</div><table class="source_code">
|
757
|
+
<tr>
|
758
|
+
<td>
|
759
|
+
<pre class="lines">
|
760
|
+
|
761
|
+
|
762
|
+
106</pre>
|
763
|
+
</td>
|
764
|
+
<td>
|
765
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 106</span>
|
766
|
+
|
767
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_complete?'>complete?</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='kw'>return</span> <span class='ivar'>@complete</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
|
768
|
+
</td>
|
769
|
+
</tr>
|
770
|
+
</table>
|
771
|
+
</div>
|
772
|
+
|
773
|
+
<div class="method_details ">
|
774
|
+
<h3 class="signature " id="value-instance_method">
|
775
|
+
|
776
|
+
#<strong>value</strong> ⇒ <tt>Object</tt>
|
777
|
+
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
</h3><div class="docstring">
|
783
|
+
<div class="discussion">
|
784
|
+
|
785
|
+
<p>Return the result of the child process, blocking if it is not yet
|
786
|
+
available. Blocking is done by calling <code>wait</code>, so the process
|
787
|
+
will be cleaned up.</p>
|
788
|
+
|
789
|
+
|
790
|
+
</div>
|
791
|
+
</div>
|
792
|
+
<div class="tags">
|
793
|
+
|
794
|
+
|
795
|
+
</div><table class="source_code">
|
796
|
+
<tr>
|
797
|
+
<td>
|
798
|
+
<pre class="lines">
|
799
|
+
|
800
|
+
|
801
|
+
111
|
802
|
+
112
|
803
|
+
113
|
804
|
+
114</pre>
|
805
|
+
</td>
|
806
|
+
<td>
|
807
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 111</span>
|
808
|
+
|
809
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_value'>value</span>
|
810
|
+
<span class='id identifier rubyid_wait'>wait</span>
|
811
|
+
<span class='kw'>return</span> <span class='ivar'>@result</span>
|
812
|
+
<span class='kw'>end</span></pre>
|
813
|
+
</td>
|
814
|
+
</tr>
|
815
|
+
</table>
|
816
|
+
</div>
|
817
|
+
|
818
|
+
<div class="method_details ">
|
819
|
+
<h3 class="signature " id="wait-instance_method">
|
820
|
+
|
821
|
+
#<strong>wait</strong> ⇒ <tt>Object</tt>
|
822
|
+
|
823
|
+
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
</h3><div class="docstring">
|
828
|
+
<div class="discussion">
|
829
|
+
|
830
|
+
<p>Block until the child process finishes, recover its result and clean up the
|
831
|
+
process. <code>wait</code> <strong>must</strong> be called for each
|
832
|
+
<code>SimpleFuture</code> to prevent zombie processes. In practice, this is
|
833
|
+
rarely a problem since <code>value</code> calls <code>wait</code> and you
|
834
|
+
usually want to get all of the values. See <code>wait_for_all</code>.</p>
|
835
|
+
|
836
|
+
<p>It is safe to call <code>wait</code> multiple times on a
|
837
|
+
<code>SimpleFuture</code>.</p>
|
838
|
+
|
839
|
+
|
840
|
+
</div>
|
841
|
+
</div>
|
842
|
+
<div class="tags">
|
843
|
+
|
844
|
+
<p class="tag_title">Raises:</p>
|
845
|
+
<ul class="raise">
|
846
|
+
|
847
|
+
<li>
|
848
|
+
|
849
|
+
|
850
|
+
<span class='type'>(<tt><span class='object_link'><a href="SimpleFuture/ChildError.html" title="SimpleFuture::ChildError (class)">ChildError</a></span></tt>)</span>
|
851
|
+
|
852
|
+
|
853
|
+
|
854
|
+
—
|
855
|
+
<div class='inline'>
|
856
|
+
<p>The child process raised an uncaught exception.</p>
|
857
|
+
</div>
|
858
|
+
|
859
|
+
</li>
|
860
|
+
|
861
|
+
<li>
|
862
|
+
|
863
|
+
|
864
|
+
<span class='type'>(<tt><span class='object_link'><a href="SimpleFuture/ResultTypeError.html" title="SimpleFuture::ResultTypeError (class)">ResultTypeError</a></span></tt>)</span>
|
865
|
+
|
866
|
+
|
867
|
+
|
868
|
+
—
|
869
|
+
<div class='inline'>
|
870
|
+
<p>Marshal cannot encode the result</p>
|
871
|
+
</div>
|
872
|
+
|
873
|
+
</li>
|
874
|
+
|
875
|
+
<li>
|
876
|
+
|
877
|
+
|
878
|
+
<span class='type'>(<tt><span class='object_link'><a href="SimpleFuture/Error.html" title="SimpleFuture::Error (class)">Error</a></span></tt>)</span>
|
879
|
+
|
880
|
+
|
881
|
+
|
882
|
+
—
|
883
|
+
<div class='inline'>
|
884
|
+
<p>An error occurred in the IPC system or child process.</p>
|
885
|
+
</div>
|
886
|
+
|
887
|
+
</li>
|
888
|
+
|
889
|
+
</ul>
|
890
|
+
|
891
|
+
</div><table class="source_code">
|
892
|
+
<tr>
|
893
|
+
<td>
|
894
|
+
<pre class="lines">
|
895
|
+
|
896
|
+
|
897
|
+
127
|
898
|
+
128
|
899
|
+
129
|
900
|
+
130
|
901
|
+
131
|
902
|
+
132
|
903
|
+
133
|
904
|
+
134
|
905
|
+
135
|
906
|
+
136
|
907
|
+
137
|
908
|
+
138
|
909
|
+
139
|
910
|
+
140
|
911
|
+
141
|
912
|
+
142
|
913
|
+
143
|
914
|
+
144
|
915
|
+
145
|
916
|
+
146
|
917
|
+
147
|
918
|
+
148
|
919
|
+
149
|
920
|
+
150
|
921
|
+
151
|
922
|
+
152
|
923
|
+
153
|
924
|
+
154
|
925
|
+
155
|
926
|
+
156
|
927
|
+
157
|
928
|
+
158
|
929
|
+
159
|
930
|
+
160
|
931
|
+
161
|
932
|
+
162
|
933
|
+
163
|
934
|
+
164
|
935
|
+
165
|
936
|
+
166</pre>
|
937
|
+
</td>
|
938
|
+
<td>
|
939
|
+
<pre class="code"><span class="info file"># File 'lib/simple-future.rb', line 127</span>
|
940
|
+
|
941
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_wait'>wait</span>
|
942
|
+
<span class='comment'># Quit if the child has already exited
|
943
|
+
</span> <span class='kw'>return</span> <span class='kw'>if</span> <span class='id identifier rubyid_complete?'>complete?</span>
|
944
|
+
|
945
|
+
<span class='comment'># Read the contents; this may block
|
946
|
+
</span> <span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='ivar'>@readPipe</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span>
|
947
|
+
|
948
|
+
<span class='comment'># Reap the child process; this shouldn't block for long
|
949
|
+
</span> <span class='const'>Process</span><span class='period'>.</span><span class='id identifier rubyid_wait'>wait</span><span class='lparen'>(</span><span class='ivar'>@pid</span><span class='rparen'>)</span>
|
950
|
+
|
951
|
+
<span class='comment'># And now we're complete, regardless of what happens next. (We
|
952
|
+
</span> <span class='comment'># set it early so that errors later on won't allow waiting again
|
953
|
+
</span> <span class='comment'># and associated mystery errors.)
|
954
|
+
</span> <span class='ivar'>@complete</span> <span class='op'>=</span> <span class='kw'>true</span>
|
955
|
+
|
956
|
+
<span class='comment'># Close and discard the pipe; we're done with it
|
957
|
+
</span> <span class='ivar'>@readPipe</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
|
958
|
+
<span class='ivar'>@readPipe</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
959
|
+
|
960
|
+
<span class='comment'># If the child process exited badly, this is an error
|
961
|
+
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="SimpleFuture/Error.html" title="SimpleFuture::Error (class)">Error</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="SimpleFuture#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Error in child process </span><span class='embexpr_beg'>#{</span><span class='ivar'>@pid</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>unless</span>
|
962
|
+
<span class='gvar'>$?</span><span class='period'>.</span><span class='id identifier rubyid_exitstatus'>exitstatus</span> <span class='op'>==</span> <span class='int'>0</span> <span class='op'>&&</span> <span class='op'>!</span><span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
963
|
+
|
964
|
+
<span class='comment'># Decode the result. If it's an exception object, that's the
|
965
|
+
</span> <span class='comment'># error that was thrown in the child and that means an error here
|
966
|
+
</span> <span class='comment'># as well.
|
967
|
+
</span> <span class='id identifier rubyid_rbox'>rbox</span> <span class='op'>=</span> <span class='const'>Marshal</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
|
968
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='id identifier rubyid_rbox'>rbox</span> <span class='kw'>if</span> <span class='id identifier rubyid_rbox'>rbox</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'><span class='object_link'><a href="SimpleFuture/ResultTypeError.html" title="SimpleFuture::ResultTypeError (class)">ResultTypeError</a></span></span>
|
969
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="SimpleFuture/ChildError.html" title="SimpleFuture::ChildError (class)">ChildError</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="SimpleFuture/ChildError.html#initialize-instance_method" title="SimpleFuture::ChildError#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Child process failed with an exception.</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='id identifier rubyid_rbox'>rbox</span><span class='rparen'>)</span> <span class='kw'>if</span>
|
970
|
+
<span class='id identifier rubyid_rbox'>rbox</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>Exception</span>
|
971
|
+
|
972
|
+
<span class='comment'># Ensure rbox is a ResultContainer. This *probably* can't happen.
|
973
|
+
</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'><span class='object_link'><a href="SimpleFuture/Error.html" title="SimpleFuture::Error (class)">Error</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="SimpleFuture#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid result object type: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_rbox'>rbox</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>unless</span>
|
974
|
+
<span class='id identifier rubyid_rbox'>rbox</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span> <span class='const'>ResultContainer</span>
|
975
|
+
|
976
|
+
<span class='comment'># Aaaaaand, retrieve the value.
|
977
|
+
</span> <span class='ivar'>@result</span> <span class='op'>=</span> <span class='id identifier rubyid_rbox'>rbox</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span>
|
978
|
+
|
979
|
+
<span class='kw'>return</span> <span class='comment'># return nil
|
980
|
+
</span><span class='kw'>end</span></pre>
|
981
|
+
</td>
|
982
|
+
</tr>
|
983
|
+
</table>
|
984
|
+
</div>
|
985
|
+
|
986
|
+
</div>
|
987
|
+
|
988
|
+
</div>
|
989
|
+
|
990
|
+
<div id="footer">
|
991
|
+
Generated on Wed Jan 17 18:36:16 2018 by
|
992
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
993
|
+
0.9.12 (ruby-2.4.3).
|
994
|
+
</div>
|
995
|
+
|
996
|
+
</div>
|
997
|
+
</body>
|
998
|
+
</html>
|