Skip to content

Commit 8b8a8a3

Browse files
authored
Merge pull request #830 from petrblaho/wrapping-executor
Adds WrappingExecutor with docs
2 parents 1075d81 + 69e6f5d commit 8b8a8a3

24 files changed

+3004
-1917
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ be obeyed though. Features developed in `concurrent-ruby-edge` are expected to m
253253
* [ErlangActor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/ErlangActor.html)
254254
Actor implementation which precisely matches Erlang actor behaviour.
255255
Requires at least Ruby 2.1 otherwise it's not loaded.
256+
* [WrappingExecutor](http://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/WrappingExecutor.html)
257+
A delegating executor which modifies each task before the task is given to
258+
the target executor it delegates to.
256259

257260
## Supported Ruby versions
258261

docs-source/channel.out.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ threads = Array.new(3) { |i| Thread.new { ch.push message: i } }
1616
sleep 0.01 # let the threads run
1717
threads
1818
# => [#<Thread:0x000003@channel.in.md:14 dead>,
19-
# #<Thread:0x000004@channel.in.md:14 dead>,
20-
# #<Thread:0x000005@channel.in.md:14 sleep_forever>]
19+
# #<Thread:0x000004@channel.in.md:14 sleep_forever>,
20+
# #<Thread:0x000005@channel.in.md:14 dead>]
2121
```
2222

2323
When message is popped the last thread continues and finishes as well.
@@ -45,7 +45,7 @@ threads
4545
ch.push message: 3
4646
# => #<Concurrent::Promises::Channel:0x000002 capacity taken 0 of 2>
4747
threads.map(&:value)
48-
# => [{:message=>1}, {:message=>2}, {:message=>3}]
48+
# => [{:message=>2}, {:message=>1}, {:message=>3}]
4949
```
5050

5151
### Promises integration
@@ -204,16 +204,16 @@ log
204204
# "producer 0 pushing 2",
205205
# "producer 1 pushing 0",
206206
# "consumer 0 got 0. payload 0 from producer 0",
207+
# "producer 0 pushing 3",
207208
# "consumer 1 got 0. payload 1 from producer 0",
209+
# "producer 1 pushing 1",
208210
# "consumer 2 got 0. payload 2 from producer 0",
209211
# "consumer 3 got 0. payload 0 from producer 1",
210-
# "producer 0 pushing 3",
211-
# "producer 1 pushing 1",
212212
# "producer 1 pushing 2",
213213
# "consumer 0 got 1. payload 3 from producer 0",
214-
# "consumer 1 got 1. payload 1 from producer 1",
215-
# "consumer 3 got 1. payload 2 from producer 1",
216214
# "producer 1 pushing 3",
215+
# "consumer 3 got 1. payload 1 from producer 1",
216+
# "consumer 1 got 1. payload 2 from producer 1",
217217
# "consumer 2 got 1. payload 3 from producer 1"]
218218
```
219219

@@ -268,20 +268,20 @@ consumers.map(&:value!) # => [:done, :done, :done, :done]
268268
# investigate log
269269
log
270270
# => ["producer 0 pushing 0",
271-
# "producer 1 pushing 0",
272271
# "producer 0 pushing 1",
272+
# "producer 1 pushing 0",
273+
# "consumer 1 got 0. payload 1 from producer 0",
274+
# "producer 0 pushing 2",
275+
# "producer 0 pushing 3",
273276
# "producer 1 pushing 1",
274277
# "consumer 0 got 0. payload 0 from producer 0",
275-
# "consumer 1 got 0. payload 0 from producer 1",
276-
# "consumer 2 got 0. payload 1 from producer 0",
277-
# "producer 0 pushing 2",
278-
# "consumer 3 got 0. payload 1 from producer 1",
278+
# "consumer 2 got 0. payload 0 from producer 1",
279279
# "producer 1 pushing 2",
280-
# "producer 0 pushing 3",
280+
# "consumer 3 got 0. payload 2 from producer 0",
281281
# "producer 1 pushing 3",
282-
# "consumer 0 got 1. payload 2 from producer 0",
283-
# "consumer 2 got 1. payload 2 from producer 1",
284282
# "consumer 1 got 1. payload 3 from producer 0",
283+
# "consumer 0 got 1. payload 1 from producer 1",
284+
# "consumer 2 got 1. payload 2 from producer 1",
285285
# "consumer 3 got 1. payload 3 from producer 1"]
286286
```
287287

docs-source/erlang_actor.out.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Although, `Promises.future { 1 + 1 }` is better suited for that purpose.
55

66
```ruby
77
actor = Concurrent::ErlangActor.spawn(type: :on_thread, name: 'addition') { 1 + 1 }
8-
# => #<Concurrent::ErlangActor::Pid:0x000002 addition terminated normally with 2>
8+
# => #<Concurrent::ErlangActor::Pid:0x000002 addition running>
99
actor.terminated.value! # => 2
1010
```
1111

docs-source/medium-example.out.rb

Lines changed: 507 additions & 362 deletions
Large diffs are not rendered by default.

docs/js/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ function mainFocus() {
275275
setTimeout(function() { $('#main').focus(); }, 10);
276276
}
277277

278+
function navigationChange() {
279+
// This works around the broken anchor navigation with the YARD template.
280+
window.onpopstate = function() {
281+
var hash = window.location.hash;
282+
if (hash !== '' && $(hash)[0]) {
283+
$(hash)[0].scrollIntoView();
284+
}
285+
};
286+
}
287+
278288
$(document).ready(function() {
279289
navResizer();
280290
navExpander();
@@ -287,6 +297,7 @@ $(document).ready(function() {
287297
constantSummaryToggle();
288298
generateTOC();
289299
mainFocus();
300+
navigationChange();
290301
});
291302

292303
})();

docs/master/Concurrent.html

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

docs/master/Concurrent/Actor.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ <h2>Sending messages</h2>
218218
Sends the message asynchronously to the actor and immediately returns
219219
<code>self</code> (the reference) allowing to chain message telling.</li>
220220
<li> <span class='object_link'><a href="Actor/Reference.html#ask-instance_method" title="Concurrent::Actor::Reference#ask (method)">Reference#ask</a></span>
221-
testing and when it returns very shortly. It can lead to deadlock if all threads in
222-
global_io_executor will block on while asking. It&#39;s fine to use it form outside of actors and
223-
global_io_executor.</li>
221+
</li>
224222
<li> <span class='object_link'><a href="Actor/Reference.html#ask!-instance_method" title="Concurrent::Actor::Reference#ask! (method)">Reference#ask!</a></span>
225223
Sends the message synchronously and blocks until the message
226224
is processed. Raises on error.</li>

docs/master/Concurrent/Actor/Reference.html

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ <h2>
177177

178178

179179

180-
<span class="summary_desc"><div class='inline'><p>testing and when it returns very shortly.</p>
180+
<span class="summary_desc"><div class='inline'><p>Supplied future.</p>
181181
</div></span>
182182

183183
</li>
@@ -687,12 +687,12 @@ <h3 class="signature first" id="==-instance_method">
687687
<pre class="lines">
688688

689689

690-
100
691-
101
692-
102</pre>
690+
95
691+
96
692+
97</pre>
693693
</td>
694694
<td>
695-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 100</span>
695+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 95</span>
696696

697697
<span class='kw'>def</span> <span class='op'>==</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
698698
<span class='id identifier rubyid_Type?'>Type?</span> <span class='id identifier rubyid_other'>other</span><span class='comma'>,</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='kw'>and</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:core</span><span class='rparen'>)</span> <span class='op'>==</span> <span class='id identifier rubyid_core'>core</span>
@@ -720,22 +720,14 @@ <h3 class="signature " id="ask-instance_method">
720720

721721
<div class="note notetag">
722722
<strong>Note:</strong>
723-
<div class='inline'><p>it&#39;s a good practice to use tell whenever possible. Ask should be used only for</p>
724-
</div>
725-
</div>
726-
727-
<div class="note notetag">
728-
<strong>Note:</strong>
729-
<div class='inline'><p>it&#39;s a good practice to use <span class='object_link'><a href="#tell-instance_method" title="Concurrent::Actor::Reference#tell (method)">#tell</a></span> whenever possible. Results can be send back with other messages.
723+
<div class='inline'><p>it&#39;s a good practice to use <span class='object_link'><a href="#tell-instance_method" title="Concurrent::Actor::Reference#tell (method)">#tell</a></span> whenever possible. Results can be sent back with other messages.
730724
Ask should be used only for testing and when it returns very shortly. It can lead to deadlock if all threads in
731725
global_io_executor will block on while asking. It&#39;s fine to use it form outside of actors and
732726
global_io_executor.</p>
733727
</div>
734728
</div>
735729

736-
<p>testing and when it returns very shortly. It can lead to deadlock if all threads in
737-
global_io_executor will block on while asking. It&#39;s fine to use it form outside of actors and
738-
global_io_executor.</p>
730+
<p>Returns supplied future</p>
739731

740732

741733
</div>
@@ -808,12 +800,12 @@ <h3 class="signature " id="ask-instance_method">
808800
<pre class="lines">
809801

810802

811-
54
812-
55
813-
56</pre>
803+
49
804+
50
805+
51</pre>
814806
</td>
815807
<td>
816-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 54</span>
808+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 49</span>
817809

818810
<span class='kw'>def</span> <span class='id identifier rubyid_ask'>ask</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span> <span class='op'>=</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'><span class='object_link'><a href="../Promises.html" title="Concurrent::Promises (module)">Promises</a></span></span><span class='period'>.</span><span class='id identifier rubyid_resolvable_future'><span class='object_link'><a href="../Promises/FactoryMethods.html#resolvable_future-instance_method" title="Concurrent::Promises::FactoryMethods#resolvable_future (method)">resolvable_future</a></span></span><span class='rparen'>)</span>
819811
<span class='id identifier rubyid_message'>message</span> <span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span>
@@ -837,7 +829,7 @@ <h3 class="signature " id="ask!-instance_method">
837829

838830
<div class="note notetag">
839831
<strong>Note:</strong>
840-
<div class='inline'><p>it&#39;s a good practice to use <span class='object_link'><a href="#tell-instance_method" title="Concurrent::Actor::Reference#tell (method)">#tell</a></span> whenever possible. Results can be send back with other messages.
832+
<div class='inline'><p>it&#39;s a good practice to use <span class='object_link'><a href="#tell-instance_method" title="Concurrent::Actor::Reference#tell (method)">#tell</a></span> whenever possible. Results can be sent back with other messages.
841833
Ask should be used only for testing and when it returns very shortly. It can lead to deadlock if all threads in
842834
global_io_executor will block on while asking. It&#39;s fine to use it form outside of actors and
843835
global_io_executor.</p>
@@ -934,12 +926,12 @@ <h3 class="signature " id="ask!-instance_method">
934926
<pre class="lines">
935927

936928

937-
75
938-
76
939-
77</pre>
929+
70
930+
71
931+
72</pre>
940932
</td>
941933
<td>
942-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 75</span>
934+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 70</span>
943935

944936
<span class='kw'>def</span> <span class='id identifier rubyid_ask!'>ask!</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span> <span class='op'>=</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'><span class='object_link'><a href="../Promises.html" title="Concurrent::Promises (module)">Promises</a></span></span><span class='period'>.</span><span class='id identifier rubyid_resolvable_future'><span class='object_link'><a href="../Promises/FactoryMethods.html#resolvable_future-instance_method" title="Concurrent::Promises::FactoryMethods#resolvable_future (method)">resolvable_future</a></span></span><span class='rparen'>)</span>
945937
<span class='id identifier rubyid_ask'>ask</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_value!'>value!</span>
@@ -980,12 +972,12 @@ <h3 class="signature " id="dead_letter_routing-instance_method">
980972
<pre class="lines">
981973

982974

983-
90
984-
91
985-
92</pre>
975+
85
976+
86
977+
87</pre>
986978
</td>
987979
<td>
988-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 90</span>
980+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 85</span>
989981

990982
<span class='kw'>def</span> <span class='id identifier rubyid_dead_letter_routing'>dead_letter_routing</span>
991983
<span class='id identifier rubyid_core'>core</span><span class='period'>.</span><span class='id identifier rubyid_dead_letter_routing'>dead_letter_routing</span>
@@ -1019,12 +1011,12 @@ <h3 class="signature " id="map-instance_method">
10191011
<pre class="lines">
10201012

10211013

1022-
79
1023-
80
1024-
81</pre>
1014+
74
1015+
75
1016+
76</pre>
10251017
</td>
10261018
<td>
1027-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 79</span>
1019+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 74</span>
10281020

10291021
<span class='kw'>def</span> <span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='id identifier rubyid_messages'>messages</span><span class='rparen'>)</span>
10301022
<span class='id identifier rubyid_messages'>messages</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_m'>m</span><span class='op'>|</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_ask'>ask</span><span class='lparen'>(</span><span class='id identifier rubyid_m'>m</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
@@ -1059,13 +1051,13 @@ <h3 class="signature " id="message-instance_method">
10591051
<pre class="lines">
10601052

10611053

1062-
84
1063-
85
1064-
86
1065-
87</pre>
1054+
79
1055+
80
1056+
81
1057+
82</pre>
10661058
</td>
10671059
<td>
1068-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 84</span>
1060+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 79</span>
10691061

10701062
<span class='kw'>def</span> <span class='id identifier rubyid_message'>message</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
10711063
<span class='id identifier rubyid_core'>core</span><span class='period'>.</span><span class='id identifier rubyid_on_envelope'>on_envelope</span> <span class='const'><span class='object_link'><a href="Envelope.html" title="Concurrent::Actor::Envelope (class)">Envelope</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Envelope.html#initialize-instance_method" title="Concurrent::Actor::Envelope#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_future'>future</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="../Actor.html" title="Concurrent::Actor (module)">Actor</a></span></span><span class='period'>.</span><span class='id identifier rubyid_current'><span class='object_link'><a href="../Actor.html#current-class_method" title="Concurrent::Actor.current (method)">current</a></span></span> <span class='op'>||</span> <span class='const'>Thread</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span><span class='comma'>,</span> <span class='kw'>self</span><span class='rparen'>)</span>
@@ -1192,12 +1184,12 @@ <h3 class="signature " id="to_s-instance_method">
11921184
<pre class="lines">
11931185

11941186

1195-
94
1196-
95
1197-
96</pre>
1187+
89
1188+
90
1189+
91</pre>
11981190
</td>
11991191
<td>
1200-
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 94</span>
1192+
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/actor/reference.rb', line 89</span>
12011193

12021194
<span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span>
12031195
<span class='id identifier rubyid_format'>format</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>%s %s (%s)&gt;</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span> <span class='kw'>super</span><span class='lbracket'>[</span><span class='int'>0</span><span class='op'>..</span><span class='op'>-</span><span class='int'>2</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_actor_class'>actor_class</span>

docs/master/Concurrent/Array.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,19 @@ <h2>Overview</h2><div class="docstring">
104104

105105
<div class="note notetag">
106106
<strong>Note:</strong>
107-
<div class='inline'><p><code>a += b</code> is <strong>not</strong> a <strong>thread-safe</strong> operation on</p>
107+
<div class='inline'><p><code>a += b</code> is <strong>not</strong> a <strong>thread-safe</strong> operation on
108+
<code>Concurrent::Array</code>. It reads array <code>a</code>, then it creates new <code>Concurrent::Array</code>
109+
which is concatenation of <code>a</code> and <code>b</code>, then it writes the concatenation to <code>a</code>.
110+
The read and write are independent operations they do not form a single atomic
111+
operation therefore when two <code>+=</code> operations are executed concurrently updates
112+
may be lost. Use <code>#concat</code> instead.</p>
108113
</div>
109114
</div>
110115

111116
<p>A thread-safe subclass of Array. This version locks against the object
112117
itself for every method call, ensuring only one thread can be reading
113118
or writing at a time. This includes iteration methods like <code>#each</code>.</p>
114119

115-
<p><code>Concurrent::Array</code>. It reads array <code>a</code>, then it creates new <code>Concurrent::Array</code>
116-
which is concatenation of <code>a</code> and <code>b</code>, then it writes the concatenation to <code>a</code>.
117-
The read and write are independent operations they do not form a single atomic
118-
operation therefore when two <code>+=</code> operations are executed concurrently updates
119-
may be lost. Use <code>#concat</code> instead.</p>
120-
121120

122121
</div>
123122
</div>

docs/master/Concurrent/ErlangActor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ <h2>Overview</h2><div class="docstring">
119119
Although, <code>Promises.future { 1 + 1 }</code> is better suited for that purpose.</p>
120120

121121
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_actor'>actor</span> <span class='op'>=</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'>ErlangActor</span><span class='period'>.</span><span class='id identifier rubyid_spawn'><span class='object_link'><a href="ErlangActor/FunctionShortcuts.html#spawn-instance_method" title="Concurrent::ErlangActor::FunctionShortcuts#spawn (method)">spawn</a></span></span><span class='lparen'>(</span><span class='label'>type:</span> <span class='symbol'>:on_thread</span><span class='comma'>,</span> <span class='label'>name:</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>addition</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='int'>1</span> <span class='op'>+</span> <span class='int'>1</span> <span class='rbrace'>}</span>
122-
<span class='comment'># =&gt; #&lt;Concurrent::ErlangActor::Pid:0x000002 addition terminated normally with 2&gt;
122+
<span class='comment'># =&gt; #&lt;Concurrent::ErlangActor::Pid:0x000002 addition running&gt;
123123
</span><span class='id identifier rubyid_actor'>actor</span><span class='period'>.</span><span class='id identifier rubyid_terminated'>terminated</span><span class='period'>.</span><span class='id identifier rubyid_value!'>value!</span> <span class='comment'># =&gt; 2
124124
</span></code></pre>
125125

0 commit comments

Comments
 (0)