concurrent-ruby/docs/1.1.0/Concurrent/Promises/Future/ThrottleIntegration.html

325 lines
14 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Concurrent::Promises::Future::ThrottleIntegration
&mdash; Concurrent Ruby
</title>
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../../../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
pathId = "Concurrent::Promises::Future::ThrottleIntegration";
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 (T)</a> &raquo;
<span class='title'><span class='object_link'><a href="../../../Concurrent.html" title="Concurrent (module)">Concurrent</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../../Promises.html" title="Concurrent::Promises (module)">Promises</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></span>
&raquo;
<span class="title">ThrottleIntegration</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::Promises::Future::ThrottleIntegration
</h1>
<div class="box_info">
<dl>
<dt>Included in:</dt>
<dd><span class='object_link'><a href="../Future.html" title="Concurrent::Promises::Future (class)">Concurrent::Promises::Future</a></span></dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib-edge/concurrent/edge/throttle.rb</dd>
</dl>
</div>
<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="#rescue_throttled_by-instance_method" title="#rescue_throttled_by (instance method)">#<strong>rescue_throttled_by</strong>(throttle, *args, &amp;block) &#x21d2; Future </a>
</span>
<span class="summary_desc"><div class='inline'><p>Behaves as <span class='object_link'><a href="../Future.html#rescue-instance_method" title="Concurrent::Promises::Future#rescue (method)">#rescue</a></span> but the it is throttled.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#then_throttled_by-instance_method" title="#then_throttled_by (instance method)">#<strong>then_throttled_by</strong>(throttle, *args, &amp;block) &#x21d2; Future </a>
</span>
<span class="summary_desc"><div class='inline'><p>Behaves as <span class='object_link'><a href="../Future.html#then-instance_method" title="Concurrent::Promises::Future#then (method)">#then</a></span> but the it is throttled.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="rescue_throttled_by-instance_method">
#<strong>rescue_throttled_by</strong>(throttle, *args, &amp;block) &#x21d2; <tt><span class='object_link'><a href="../Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Behaves as <span class='object_link'><a href="../Future.html#rescue-instance_method" title="Concurrent::Promises::Future#rescue (method)">Concurrent::Promises::Future#rescue</a></span> but the it is throttled.</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="../Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></tt>)</span>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="../Future.html#rescue-instance_method" title="Concurrent::Promises::Future#rescue (method)">Concurrent::Promises::Future#rescue</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
191
192
193</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/edge/throttle.rb', line 191</span>
<span class='kw'>def</span> <span class='id identifier rubyid_rescue_throttled_by'>rescue_throttled_by</span><span class='lparen'>(</span><span class='id identifier rubyid_throttle'>throttle</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_throttled_by'>throttled_by</span><span class='lparen'>(</span><span class='id identifier rubyid_throttle'>throttle</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_trigger'>trigger</span><span class='op'>|</span> <span class='id identifier rubyid_trigger'>trigger</span><span class='period'>.</span><span class='id identifier rubyid_rescue'>rescue</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="then_throttled_by-instance_method">
#<strong>then_throttled_by</strong>(throttle, *args, &amp;block) &#x21d2; <tt><span class='object_link'><a href="../Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Behaves as <span class='object_link'><a href="../Future.html#then-instance_method" title="Concurrent::Promises::Future#then (method)">Concurrent::Promises::Future#then</a></span> but the it is throttled.</p>
</div>
</div>
<div class="tags">
<div class="examples">
<p class="tag_title">Examples:</p>
<pre class="example code"><code><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='int'>1</span><span class='op'>..</span><span class='int'>5</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_a'>to_a</span>
<span class='id identifier rubyid_db'>db</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_reduce'>reduce</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_h'>h</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_h'>h</span><span class='period'>.</span><span class='id identifier rubyid_update'>update</span> <span class='id identifier rubyid_v'>v</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='rbrace'>}</span>
<span class='id identifier rubyid_max_two'>max_two</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../../Throttle.html" title="Concurrent::Throttle (class)">Throttle</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="../../Synchronization/Object.html#new-class_method" title="Concurrent::Synchronization::Object.new (method)">new</a></span></span> <span class='int'>2</span>
<span class='id identifier rubyid_futures'>futures</span> <span class='op'>=</span> <span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_data'>data</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_future'><span class='object_link'><a href="../FactoryMethods.html#future-instance_method" title="Concurrent::Promises::FactoryMethods#future (method)">future</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_data'>data</span><span class='op'>|</span>
<span class='comment'># un-throttled, concurrency level equal data.size
</span> <span class='id identifier rubyid_data'>data</span> <span class='op'>+</span> <span class='int'>1</span>
<span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_then_throttled_by'>then_throttled_by</span><span class='lparen'>(</span><span class='id identifier rubyid_max_two'>max_two</span><span class='comma'>,</span> <span class='id identifier rubyid_db'>db</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_v'>v</span><span class='comma'>,</span> <span class='id identifier rubyid_db'>db</span><span class='op'>|</span>
<span class='comment'># throttled, only 2 tasks executed at the same time
</span> <span class='comment'># e.g. limiting access to db
</span> <span class='id identifier rubyid_db'>db</span><span class='lbracket'>[</span><span class='id identifier rubyid_v'>v</span><span class='rbracket'>]</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='id identifier rubyid_futures'>futures</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='symbol'>:value!</span><span class='rparen'>)</span> <span class='comment'># =&gt; [2, 3, 4, 5, nil]</span></code></pre>
</div>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="../Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></tt>)</span>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="../Future.html#then-instance_method" title="Concurrent::Promises::Future#then (method)">Concurrent::Promises::Future#then</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
184
185
186</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib-edge/concurrent/edge/throttle.rb', line 184</span>
<span class='kw'>def</span> <span class='id identifier rubyid_then_throttled_by'>then_throttled_by</span><span class='lparen'>(</span><span class='id identifier rubyid_throttle'>throttle</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_throttled_by'>throttled_by</span><span class='lparen'>(</span><span class='id identifier rubyid_throttle'>throttle</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_trigger'>trigger</span><span class='op'>|</span> <span class='id identifier rubyid_trigger'>trigger</span><span class='period'>.</span><span class='id identifier rubyid_then'>then</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> <span class='rbrace'>}</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>