1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 3<title>eager<T>/atomic_eager<T> - Boost.Outcome documentation</title> 4<link rel="stylesheet" href="../../css/boost.css" type="text/css"> 5<meta name="generator" content="Hugo 0.52 with Boostdoc theme"> 6<meta name="viewport" content="width=device-width,initial-scale=1.0"/> 7 8<link rel="icon" href="../../images/favicon.ico" type="image/ico"/> 9<body><div class="spirit-nav"> 10<a accesskey="p" href="../../reference/aliases/default_policy.html"><img src="../../images/prev.png" alt="Prev"></a> 11 <a accesskey="u" href="../../reference/aliases.html"><img src="../../images/up.png" alt="Up"></a> 12 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/aliases/lazy.html"><img src="../../images/next.png" alt="Next"></a></div><div id="content"> 13 <div class="titlepage"><div><div><h1 style="clear: both"><code>eager<T>/atomic_eager<T></code></h1></div></div></div> 14 <p>This is very similar to <a href="../../reference/aliases/lazy.html" class="api-reference"><code>lazy<T></code></a> 15, except that execution of the <code>eager<T></code> 16returning function begins immediately, and if the function never suspends during the 17course of its execution, no suspend-resume cycle occurs. Functions which return <code>eager<T></code> 18are therefore suitable for tasks which <em>may</em> require suspension, but will often complete 19immediately.</p> 20 21<p><code>atomic_eager<T></code> is like <code>eager<T></code>, except that the setting of the coroutine result 22performs an atomic release, whilst the checking of whether the coroutine has finished 23is an atomic acquire.</p> 24 25<p>Example of use (must be called from within a coroutinised function):</p> 26<div class="highlight"><pre class="chroma"><code class="language-c++" data-lang="c++"><span class="n">eager</span><span class="o"><</span><span class="kt">int</span><span class="o">></span> <span class="n">func</span><span class="p">(</span><span class="kt">int</span> <span class="n">x</span><span class="p">)</span> 27<span class="p">{</span> 28 <span class="n">co_return</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> 29<span class="p">}</span> 30<span class="p">...</span> 31<span class="c1">// Executes like a non-coroutine function i.e. r is immediately set to 6. 32</span><span class="c1"></span><span class="kt">int</span> <span class="n">r</span> <span class="o">=</span> <span class="n">co_await</span> <span class="n">func</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span> 33</code></pre></div> 34<p><code>eager<T></code> has special semantics if <code>T</code> is a type capable of constructing from 35an <code>exception_ptr</code> or <code>error_code</code> – any exceptions thrown during the function’s body 36are sent via <code>T</code>, preferably via the error code route if <a href="../../reference/functions/error_from_exception.html" class="api-reference"><code>error_from_exception(</code></a> 37<code>)</code> 38successfully matches the exception throw. This means that a <a href="../../reference/types/basic_result.html" class="api-reference"><code>basic_result<T, E, NoValuePolicy></code></a> 39 40or <a href="../../reference/types/basic_outcome.html" class="api-reference"><code>basic_outcome<T, EC, EP, NoValuePolicy></code></a> 41 where one of its types is 42is compatible will have its <code>.error()</code> or <code>.exception()</code> set.</p> 43 44<p>Note that <code>eager<T></code> does not otherwise transport exception throws, and rethrows 45any exceptions thrown within the coroutine body through the coroutine machinery. 46This does not produce reliable consequences in current C++ compilers. You should 47therefore wrap the coroutine body in a <code>try...catch</code> if <code>T</code> is not able to transport 48exceptions on its own.</p> 49 50<p><em>Requires</em>: C++ coroutines to be available in your compiler.</p> 51 52<p><em>Namespace</em>: <code>BOOST_OUTCOME_V2_NAMESPACE::awaitables</code></p> 53 54<p><em>Header</em>: <code><boost/outcome/coroutine_support.hpp></code></p> 55 56 57 </div><p><small>Last revised: October 04, 2019 at 15:58:37 +0100</small></p> 58<hr> 59<div class="spirit-nav"> 60<a accesskey="p" href="../../reference/aliases/default_policy.html"><img src="../../images/prev.png" alt="Prev"></a> 61 <a accesskey="u" href="../../reference/aliases.html"><img src="../../images/up.png" alt="Up"></a> 62 <a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../../reference/aliases/lazy.html"><img src="../../images/next.png" alt="Next"></a></div></body> 63</html> 64