File: Async.html

package info (click to toggle)
ruby-concurrent 1.1.6%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 30,284 kB
  • sloc: ruby: 30,875; java: 6,117; javascript: 1,114; ansic: 288; makefile: 10; sh: 6
file content (774 lines) | stat: -rw-r--r-- 29,251 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
  Module: Concurrent::Async
  
    &mdash; Concurrent Ruby
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" />

<script type="text/javascript">
  pathId = "Concurrent::Async";
  relpath = '../';
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div class="nav_wrap">
      <iframe id="nav" src="../class_list.html?1"></iframe>
      <div id="resizer"></div>
    </div>

    <div id="main" tabindex="-1">
      <div id="header">
        <div id="menu">
  
    <a href="../_index.html">Index (A)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span>
     &raquo; 
    <span class="title">Async</span>
  
</div>

        <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">

        <svg width="24" height="24">
          <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
          <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
        </svg>
    </a>
  
</div>
        <div class="clear"></div>
      </div>

      <div id="content"><h1>Module: Concurrent::Async
  
  
  
</h1>
<div class="box_info">
  

  
  
  
  
  

  

  
  <dl>
    <dt>Defined in:</dt>
    <dd>lib/concurrent-ruby/concurrent/async.rb</dd>
  </dl>
  
</div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    <p>A mixin module that provides simple asynchronous behavior to a class,
turning it into a simple actor. Loosely based on Erlang&#39;s
<a href="http://www.erlang.org/doc/man/gen_server.html">gen_server</a>, but without
supervision or linking.</p>

<p>A more feature-rich <span class='object_link'><a href="Actor.html" title="Concurrent::Actor (module)">Actor</a></span> is also available when the
capabilities of <code>Async</code> are too limited.</p>

<pre class="code cucumber"><code class="cucumber">Feature:
  As a stateful, plain old Ruby class
  I want safe, asynchronous behavior
  So my long-running methods don&#39;t block the main thread
</code></pre>

<p>The <code>Async</code> module is a way to mix simple yet powerful asynchronous
capabilities into any plain old Ruby object or class, turning each object
into a simple Actor. Method calls are processed on a background thread. The
caller is free to perform other actions while processing occurs in the
background.</p>

<p>Method calls to the asynchronous object are made via two proxy methods:
<code>async</code> (alias <code>cast</code>) and <code>await</code> (alias <code>call</code>). These proxy methods post
the method call to the object&#39;s background thread and return a &quot;future&quot;
which will eventually contain the result of the method call.</p>

<p>This behavior is loosely patterned after Erlang&#39;s <code>gen_server</code> behavior.
When an Erlang module implements the <code>gen_server</code> behavior it becomes
inherently asynchronous. The <code>start</code> or <code>start_link</code> function spawns a
process (similar to a thread but much more lightweight and efficient) and
returns the ID of the process. Using the process ID, other processes can
send messages to the <code>gen_server</code> via the <code>cast</code> and <code>call</code> methods. Unlike
Erlang&#39;s <code>gen_server</code>, however, <code>Async</code> classes do not support linking or
supervision trees.</p>

<h2>Basic Usage</h2>

<p>When this module is mixed into a class, objects of the class become inherently
asynchronous. Each object gets its own background thread on which to post
asynchronous method calls. Asynchronous method calls are executed in the
background one at a time in the order they are received.</p>

<p>To create an asynchronous class, simply mix in the <code>Concurrent::Async</code> module:</p>

<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Hello</span>
  <span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span><span class='op'>::</span><span class='const'>Async</span>

  <span class='kw'>def</span> <span class='id identifier rubyid_hello'>hello</span><span class='lparen'>(</span><span class='id identifier rubyid_name'>name</span><span class='rparen'>)</span>
    <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Hello, </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>

<p>When defining a constructor it is critical that the first line be a call to
<code>super</code> with no arguments. The <code>super</code> method initializes the background
thread and other asynchronous components.</p>

<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>BackgroundLogger</span>
  <span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span><span class='op'>::</span><span class='const'>Async</span>

  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_level'>level</span><span class='rparen'>)</span>
    <span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
    <span class='ivar'>@logger</span> <span class='op'>=</span> <span class='const'>Logger</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='const'>STDOUT</span><span class='rparen'>)</span>
    <span class='ivar'>@logger</span><span class='period'>.</span><span class='id identifier rubyid_level'>level</span> <span class='op'>=</span> <span class='id identifier rubyid_level'>level</span>
  <span class='kw'>end</span>

  <span class='kw'>def</span> <span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
    <span class='ivar'>@logger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
  <span class='kw'>end</span>
<span class='kw'>end</span>
</code></pre>

<p>Mixing this module into a class provides each object two proxy methods:
<code>async</code> and <code>await</code>. These methods are thread safe with respect to the
enclosing object. The former proxy allows methods to be called
asynchronously by posting to the object&#39;s internal thread. The latter proxy
allows a method to be called synchronously but does so safely with respect
to any pending asynchronous method calls and ensures proper ordering. Both
methods return a <span class='object_link'><a href="IVar.html" title="Concurrent::IVar (class)">IVar</a></span> which can be inspected for the result
of the proxied method call. Calling a method with <code>async</code> will return a
<code>:pending</code> <code>IVar</code> whereas <code>await</code> will return a <code>:complete</code> <code>IVar</code>.</p>

<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>Echo</span>
  <span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span><span class='op'>::</span><span class='const'>Async</span>

  <span class='kw'>def</span> <span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>
<span class='kw'>end</span>

<span class='id identifier rubyid_horn'>horn</span> <span class='op'>=</span> <span class='const'>Echo</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>zero</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>      <span class='comment'># synchronous, not thread-safe
</span>                       <span class='comment'># returns the actual return value of the method
</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>one</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># asynchronous, non-blocking, thread-safe
</span>                       <span class='comment'># returns an IVar in the :pending state
</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_await'>await</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>two</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># synchronous, blocking, thread-safe
</span>                       <span class='comment'># returns an IVar in the :complete state
</span></code></pre>

<h2>Let It Fail</h2>

<p>The <code>async</code> and <code>await</code> proxy methods have built-in error protection based
on Erlang&#39;s famous &quot;let it fail&quot; philosophy. Instance methods should not be
programmed defensively. When an exception is raised by a delegated method
the proxy will rescue the exception, expose it to the caller as the <code>reason</code>
attribute of the returned future, then process the next method call.</p>

<h2>Calling Methods Internally</h2>

<p>External method calls should <em>always</em> use the <code>async</code> and <code>await</code> proxy
methods. When one method calls another method, the <code>async</code> proxy should
rarely be used and the <code>await</code> proxy should <em>never</em> be used.</p>

<p>When an object calls one of its own methods using the <code>await</code> proxy the
second call will be enqueued <em>behind</em> the currently running method call.
Any attempt to wait on the result will fail as the second call will never
run until after the current call completes.</p>

<p>Calling a method using the <code>await</code> proxy from within a method that was
itself called using <code>async</code> or <code>await</code> will irreversibly deadlock the
object. Do <em>not</em> do this, ever.</p>

<h2>Instance Variables and Attribute Accessors</h2>

<p>Instance variables do not need to be thread-safe so long as they are private.
Asynchronous method calls are processed in the order they are received and
are processed one at a time. Therefore private instance variables can only
be accessed by one thread at a time. This is inherently thread-safe.</p>

<p>When using private instance variables within asynchronous methods, the best
practice is to read the instance variable into a local variable at the start
of the method then update the instance variable at the <em>end</em> of the method.
This way, should an exception be raised during method execution the internal
state of the object will not have been changed.</p>

<h3>Reader Attributes</h3>

<p>The use of <code>attr_reader</code> is discouraged. Internal state exposed externally,
when necessary, should be done through accessor methods. The instance
variables exposed by these methods <em>must</em> be thread-safe, or they must be
called using the <code>async</code> and <code>await</code> proxy methods. These two approaches are
subtly different.</p>

<p>When internal state is accessed via the <code>async</code> and <code>await</code> proxy methods,
the returned value represents the object&#39;s state <em>at the time the call is
processed</em>, which may <em>not</em> be the state of the object at the time the call
is made.</p>

<p>To get the state <em>at the current</em> time, irrespective of an enqueued method
calls, a reader method must be called directly. This is inherently unsafe
unless the instance variable is itself thread-safe, preferably using one
of the thread-safe classes within this library. Because the thread-safe
classes within this library are internally-locking or non-locking, they can
be safely used from within asynchronous methods without causing deadlocks.</p>

<p>Generally speaking, the best practice is to <em>not</em> expose internal state via
reader methods. The best practice is to simply use the method&#39;s return value.</p>

<h3>Writer Attributes</h3>

<p>Writer attributes should never be used with asynchronous classes. Changing
the state externally, even when done in the thread-safe way, is not logically
consistent. Changes to state need to be timed with respect to all asynchronous
method calls which my be in-process or enqueued. The only safe practice is to
pass all necessary data to each method as arguments and let the method update
the internal state as necessary.</p>

<h2>Class Constants, Variables, and Methods</h2>

<h3>Class Constants</h3>

<p>Class constants do not need to be thread-safe. Since they are read-only and
immutable they may be safely read both externally and from within
asynchronous methods.</p>

<h3>Class Variables</h3>

<p>Class variables should be avoided. Class variables represent shared state.
Shared state is anathema to concurrency. Should there be a need to share
state using class variables they <em>must</em> be thread-safe, preferably
using the thread-safe classes within this library. When updating class
variables, never assign a new value/object to the variable itself. Assignment
is not thread-safe in Ruby. Instead, use the thread-safe update functions
of the variable itself to change the value.</p>

<p>The best practice is to <em>never</em> use class variables with <code>Async</code> classes.</p>

<h3>Class Methods</h3>

<p>Class methods which are pure functions are safe. Class methods which modify
class variables should be avoided, for all the reasons listed above.</p>

<h2>An Important Note About Thread Safe Guarantees</h2>

<blockquote>
<p>Thread safe guarantees can only be made when asynchronous method calls
are not mixed with direct method calls. Use only direct method calls
when the object is used exclusively on a single thread. Use only
<code>async</code> and <code>await</code> when the object is shared between threads. Once you
call a method using <code>async</code> or <code>await</code>, you should no longer call methods
directly on the object. Use <code>async</code> and <code>await</code> exclusively from then on.</p>
</blockquote>


  </div>
</div>
<div class="tags">
  
  <div class="examples">
    <p class="tag_title">Examples:</p>
    
      
      <pre class="example code"><code>
<span class='kw'>class</span> <span class='const'>Echo</span>
  <span class='id identifier rubyid_include'>include</span> <span class='const'><span class='object_link'><a href="../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span><span class='op'>::</span><span class='const'>Async</span>

  <span class='kw'>def</span> <span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span>
    <span class='id identifier rubyid_print'>print</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_msg'>msg</span><span class='embexpr_end'>}</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>
<span class='kw'>end</span>

<span class='id identifier rubyid_horn'>horn</span> <span class='op'>=</span> <span class='const'>Echo</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>zero</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>      <span class='comment'># synchronous, not thread-safe
</span>                       <span class='comment'># returns the actual return value of the method
</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_async'>async</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>one</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># asynchronous, non-blocking, thread-safe
</span>                       <span class='comment'># returns an IVar in the :pending state
</span>
<span class='id identifier rubyid_horn'>horn</span><span class='period'>.</span><span class='id identifier rubyid_await'>await</span><span class='period'>.</span><span class='id identifier rubyid_echo'>echo</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>two</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='comment'># synchronous, blocking, thread-safe
</span>                       <span class='comment'># returns an IVar in the :complete state</span></code></pre>
    
  </div>


  <p class="tag_title">See Also:</p>
  <ul class="see">
    
      <li><span class='object_link'><a href="Actor.html" title="Concurrent::Actor (module)">Actor</a></span></li>
    
      <li><a href="https://en.wikipedia.org/wiki/Actor_model" target="_parent" title="&quot;Actor Model&quot; at Wikipedia">"Actor Model" at Wikipedia</a></li>
    
      <li><a href="http://www.erlang.org/doc/man/gen_server.html" target="_parent" title="Erlang gen_server">Erlang gen_server</a></li>
    
      <li><a href="http://c2.com/cgi/wiki?LetItCrash" target="_parent" title="&quot;Let It Crash&quot; at http://c2.com/">"Let It Crash" at http://c2.com/</a></li>
    
  </ul>

</div>






  
    <h2>
      Class Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#new-class_method" title="new (class method)">.<strong>new</strong>(*args, &amp;block)  &#x21d2; Object </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Instanciate a new object and ensure proper initialization of the synchronization mechanisms.</p>
</div></span>
  
</li>

      
    </ul>
  
    <h2>
      Instance Method Summary
      <small><a href="#" class="summary_toggle">collapse</a></small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#async-instance_method" title="#async (instance method)">#<strong>async</strong>  &#x21d2; Concurrent::IVar </a>
    

    
      (also: #cast)
    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Causes the chained method call to be performed asynchronously on the object&#39;s thread.</p>
</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#await-instance_method" title="#await (instance method)">#<strong>await</strong>  &#x21d2; Concurrent::IVar </a>
    

    
      (also: #call)
    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'><p>Causes the chained method call to be performed synchronously on the current thread.</p>
</div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="new-class_method">
  
    .<strong>new</strong>(*args, &amp;block)  &#x21d2; <tt>Object</tt> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    <p>Instanciate a new object and ensure proper initialization of the
synchronization mechanisms.</p>


  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>args</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Array.html" title="Concurrent::Array (class)">Array</a></span>&lt;Object&gt;</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>Zero or more arguments to be passed to the
object&#39;s initializer.</p>
</div>
      
    </li>
  
    <li>
      
        <span class='name'>block</span>
      
      
        <span class='type'>(<tt>Proc</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>Optional block to pass to the object&#39;s initializer.</p>
</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt>Object</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>A properly initialized object of the asynchronous class.</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/concurrent-ruby/concurrent/async.rb', line 239</span>

</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="async-instance_method">
  
    #<strong>async</strong>  &#x21d2; <tt><span class='object_link'><a href="IVar.html" title="Concurrent::IVar (class)">Concurrent::IVar</a></span></tt> 
  

  
    <span class="aliases">Also known as:
    <span class="names"><span id='cast-instance_method'>cast</span></span>
    </span>
  

  
</h3><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong>
    <div class='inline'><p>The method call is guaranteed to be thread safe with respect to
all other method calls against the same object that are called with
either <code>async</code> or <code>await</code>. The mutable nature of Ruby references
(and object orientation in general) prevent any other thread safety
guarantees. Do NOT mix direct method calls with delegated method calls.
Use <em>only</em> delegated method calls when sharing the object between threads.</p>
</div>
  </div>

<p>Causes the chained method call to be performed asynchronously on the
object&#39;s thread. The delegated method will return a future in the
<code>:pending</code> state and the method call will have been scheduled on the
object&#39;s thread. The final disposition of the method call can be obtained
by inspecting the returned future.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="IVar.html" title="Concurrent::IVar (class)">Concurrent::IVar</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the pending result of the asynchronous operation</p>
</div>
      
    </li>
  
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>NameError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the object does not respond to the requested method</p>
</div>
      
    </li>
  
    <li>
      
      
        <span class='type'>(<tt>ArgumentError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the given <code>args</code> do not match the arity of
the requested method</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


422
423
424</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/concurrent-ruby/concurrent/async.rb', line 422</span>

<span class='kw'>def</span> <span class='id identifier rubyid_async'>async</span>
  <span class='ivar'>@__async_delegator__</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="await-instance_method">
  
    #<strong>await</strong>  &#x21d2; <tt><span class='object_link'><a href="IVar.html" title="Concurrent::IVar (class)">Concurrent::IVar</a></span></tt> 
  

  
    <span class="aliases">Also known as:
    <span class="names"><span id='call-instance_method'>call</span></span>
    </span>
  

  
</h3><div class="docstring">
  <div class="discussion">
    
  <div class="note notetag">
    <strong>Note:</strong>
    <div class='inline'><p>The method call is guaranteed to be thread safe with respect to
all other method calls against the same object that are called with
either <code>async</code> or <code>await</code>. The mutable nature of Ruby references
(and object orientation in general) prevent any other thread safety
guarantees. Do NOT mix direct method calls with delegated method calls.
Use <em>only</em> delegated method calls when sharing the object between threads.</p>
</div>
  </div>

<p>Causes the chained method call to be performed synchronously on the
current thread. The delegated will return a future in either the
<code>:fulfilled</code> or <code>:rejected</code> state and the delegated method will have
completed. The final disposition of the delegated method can be obtained
by inspecting the returned future.</p>


  </div>
</div>
<div class="tags">
  
<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="IVar.html" title="Concurrent::IVar (class)">Concurrent::IVar</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the completed result of the synchronous operation</p>
</div>
      
    </li>
  
</ul>
<p class="tag_title">Raises:</p>
<ul class="raise">
  
    <li>
      
      
        <span class='type'>(<tt>NameError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the object does not respond to the requested method</p>
</div>
      
    </li>
  
    <li>
      
      
        <span class='type'>(<tt>ArgumentError</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'><p>the given <code>args</code> do not match the arity of the
requested method</p>
</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


440
441
442</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/concurrent-ruby/concurrent/async.rb', line 440</span>

<span class='kw'>def</span> <span class='id identifier rubyid_await'>await</span>
  <span class='ivar'>@__await_delegator__</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

      <div id="footer">
  Generated by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_blank">yard</a>.
</div>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-57940973-1', 'auto');
  ga('send', 'pageview');

</script>

    </div>
  </body>
</html>