concurrent-ruby/docs/1.1.0/Concurrent/Promises/Event.html

768 lines
22 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Class: Concurrent::Promises::Event
&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::Event";
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 (E)</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">Event</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>Class: Concurrent::Promises::Event
</h1>
<div class="box_info">
<dl>
<dt>Inherits:</dt>
<dd>
<span class="inheritName"><span class='object_link'><a href="AbstractEventFuture.html" title="Concurrent::Promises::AbstractEventFuture (class)">AbstractEventFuture</a></span></span>
<ul class="fullTree">
<li>Object</li>
<li class="next"><span class='object_link'><a href="../Synchronization/Object.html" title="Concurrent::Synchronization::Object (class)">Synchronization::Object</a></span></li>
<li class="next"><span class='object_link'><a href="AbstractEventFuture.html" title="Concurrent::Promises::AbstractEventFuture (class)">AbstractEventFuture</a></span></li>
<li class="next">Concurrent::Promises::Event</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
</dl>
<dl>
<dt>Defined in:</dt>
<dd>lib/concurrent/promises.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Represents an event which will happen in future (will be resolved). The event is either
pending or resolved. It should be always resolved. Use <span class='object_link'><a href="Future.html" title="Concurrent::Promises::Future (class)">Future</a></span> to communicate rejections and
cancellation.</p>
</div>
</div>
<div class="tags">
</div><div id="subclasses">
<h2>Direct Known Subclasses</h2>
<p class="children"><span class='object_link'><a href="ResolvableEvent.html" title="Concurrent::Promises::ResolvableEvent (class)">ResolvableEvent</a></span></p>
</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="#any-instance_method" title="#any (instance method)">#<strong>any</strong>(event_or_future) &#x21d2; Event </a>
(also: #|)
</span>
<span class="summary_desc"><div class='inline'><p>Creates a new event which will be resolved when the first of receiver, <code>event_or_future</code> resolves.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#delay-instance_method" title="#delay (instance method)">#<strong>delay</strong> &#x21d2; Event </a>
</span>
<span class="summary_desc"><div class='inline'><p>Creates new event dependent on receiver which will not evaluate until touched, see <span class='object_link'><a href="AbstractEventFuture.html#touch-instance_method" title="Concurrent::Promises::AbstractEventFuture#touch (method)">AbstractEventFuture#touch</a></span>.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#schedule-instance_method" title="#schedule (instance method)">#<strong>schedule</strong>(intended_time) &#x21d2; Event </a>
</span>
<span class="summary_desc"><div class='inline'><p>Creates new event dependent on receiver scheduled to execute on/in intended_time.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#to_event-instance_method" title="#to_event (instance method)">#<strong>to_event</strong> &#x21d2; Event </a>
</span>
<span class="summary_desc"><div class='inline'><p>Returns self, since this is event.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#to_future-instance_method" title="#to_future (instance method)">#<strong>to_future</strong> &#x21d2; Future </a>
</span>
<span class="summary_desc"><div class='inline'><p>Converts event to a future.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#with_default_executor-instance_method" title="#with_default_executor (instance method)">#<strong>with_default_executor</strong>(executor) &#x21d2; Event </a>
</span>
<span class="summary_desc"><div class='inline'><p>Crates new object with same class with the executor set as its new default executor.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#zip-instance_method" title="#zip (instance method)">#<strong>zip</strong>(other) &#x21d2; Future, Event </a>
(also: #&amp;)
</span>
<span class="summary_desc"><div class='inline'><p>Creates a new event or a future which will be resolved when receiver and other are.</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="any-instance_method">
#<strong>any</strong>(event_or_future) &#x21d2; <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
<span class="aliases">Also known as:
<span class="names"><span id='|-instance_method'>|</span></span>
</span>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new event which will be resolved when the first of receiver, <code>event_or_future</code>
resolves.</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="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
818
819
820</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 818</span>
<span class='kw'>def</span> <span class='id identifier rubyid_any'>any</span><span class='lparen'>(</span><span class='id identifier rubyid_event_or_future'>event_or_future</span><span class='rparen'>)</span>
<span class='const'>AnyResolvedEventPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by2'>new_blocked_by2</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_event_or_future'>event_or_future</span><span class='comma'>,</span> <span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="delay-instance_method">
#<strong>delay</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates new event dependent on receiver which will not evaluate until touched, see <span class='object_link'><a href="AbstractEventFuture.html#touch-instance_method" title="Concurrent::Promises::AbstractEventFuture#touch (method)">AbstractEventFuture#touch</a></span>.
In other words, it inserts delay into the chain of Futures making rest of it lazy evaluated.</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="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
828
829
830
831</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 828</span>
<span class='kw'>def</span> <span class='id identifier rubyid_delay'>delay</span>
<span class='id identifier rubyid_event'>event</span> <span class='op'>=</span> <span class='const'>DelayPromise</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='lparen'>(</span><span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='const'>ZipEventEventPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by2'>new_blocked_by2</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_event'>event</span><span class='comma'>,</span> <span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="schedule-instance_method">
#<strong>schedule</strong>(intended_time) &#x21d2; <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Creates new event dependent on receiver scheduled to execute on/in intended_time.
In time is interpreted from the moment the receiver is resolved, therefore it inserts
delay into the chain.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>intended_time</span>
<span class='type'>(<tt>Numeric</tt>, <tt>Time</tt>)</span>
&mdash;
<div class='inline'><p><code>Numeric</code> means to run in <code>intended_time</code> seconds.
<code>Time</code> means to run on <code>intended_time</code>.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
840
841
842
843
844
845</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 840</span>
<span class='kw'>def</span> <span class='id identifier rubyid_schedule'>schedule</span><span class='lparen'>(</span><span class='id identifier rubyid_intended_time'>intended_time</span><span class='rparen'>)</span>
<span class='id identifier rubyid_chain'>chain</span> <span class='kw'>do</span>
<span class='id identifier rubyid_event'>event</span> <span class='op'>=</span> <span class='const'>ScheduledPromise</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='lparen'>(</span><span class='ivar'>@DefaultExecutor</span><span class='comma'>,</span> <span class='id identifier rubyid_intended_time'>intended_time</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='const'>ZipEventEventPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by2'>new_blocked_by2</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_event'>event</span><span class='comma'>,</span> <span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_flat_event'>flat_event</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="to_event-instance_method">
#<strong>to_event</strong> &#x21d2; <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Returns self, since this is event</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="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
858
859
860</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 858</span>
<span class='kw'>def</span> <span class='id identifier rubyid_to_event'>to_event</span>
<span class='kw'>self</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="to_future-instance_method">
#<strong>to_future</strong> &#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>Converts event to a future. The future is fulfilled when the event is resolved, the future may never fail.</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>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
850
851
852
853
854</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 850</span>
<span class='kw'>def</span> <span class='id identifier rubyid_to_future'>to_future</span>
<span class='id identifier rubyid_future'>future</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="FactoryMethods.html#resolvable_future-instance_method" title="Concurrent::Promises::FactoryMethods#resolvable_future (method)">resolvable_future</a></span></span>
<span class='kw'>ensure</span>
<span class='id identifier rubyid_chain_resolvable'>chain_resolvable</span><span class='lparen'>(</span><span class='id identifier rubyid_future'>future</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="with_default_executor-instance_method">
#<strong>with_default_executor</strong>(executor) &#x21d2; <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
</h3><div class="docstring">
<div class="discussion">
<p>Crates new object with same class with the executor set as its new default executor.
Any futures depending on it will use the new default executor.</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="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
864
865
866</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 864</span>
<span class='kw'>def</span> <span class='id identifier rubyid_with_default_executor'>with_default_executor</span><span class='lparen'>(</span><span class='id identifier rubyid_executor'>executor</span><span class='rparen'>)</span>
<span class='const'>EventWrapperPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by1'>new_blocked_by1</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_executor'>executor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="zip-instance_method">
#<strong>zip</strong>(other) &#x21d2; <tt><span class='object_link'><a href="Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></tt>, <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>
<span class="aliases">Also known as:
<span class="names"><span id='&-instance_method'>&amp;</span></span>
</span>
</h3><div class="docstring">
<div class="discussion">
<p>Creates a new event or a future which will be resolved when receiver and other are.
Returns an event if receiver and other are events, otherwise returns a future.
If just one of the parties is Future then the result
of the returned future is equal to the result of the supplied future. If both are futures
then the result is as described in <span class='object_link'><a href="FactoryMethods.html#zip_futures_on-instance_method" title="Concurrent::Promises::FactoryMethods#zip_futures_on (method)">FactoryMethods#zip_futures_on</a></span>.</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>, <tt><span class='object_link'><a href="" title="Concurrent::Promises::Event (class)">Event</a></span></tt>)</span>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
804
805
806
807
808
809
810</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/concurrent/promises.rb', line 804</span>
<span class='kw'>def</span> <span class='id identifier rubyid_zip'>zip</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='rparen'>)</span>
<span class='kw'>if</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Future.html" title="Concurrent::Promises::Future (class)">Future</a></span></span><span class='rparen'>)</span>
<span class='const'>ZipFutureEventPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by2'>new_blocked_by2</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='comma'>,</span> <span class='kw'>self</span><span class='comma'>,</span> <span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_future'>future</span>
<span class='kw'>else</span>
<span class='const'>ZipEventEventPromise</span><span class='period'>.</span><span class='id identifier rubyid_new_blocked_by2'>new_blocked_by2</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_other'>other</span><span class='comma'>,</span> <span class='ivar'>@DefaultExecutor</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_event'>event</span>
<span class='kw'>end</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>