-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying to gh-pages from @ d01727f 🚀
- Loading branch information
1 parent
779c0c0
commit e04ca49
Showing
10 changed files
with
207 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=11"/> | ||
<meta name="generator" content="Doxygen 1.9.6"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<title>beman::execution26: intro-examples</title> | ||
<link href="tabs.css" rel="stylesheet" type="text/css"/> | ||
<script type="text/javascript" src="jquery.js"></script> | ||
<script type="text/javascript" src="dynsections.js"></script> | ||
<link href="search/search.css" rel="stylesheet" type="text/css"/> | ||
<script type="text/javascript" src="search/searchdata.js"></script> | ||
<script type="text/javascript" src="search/search.js"></script> | ||
<link href="doxygen.css" rel="stylesheet" type="text/css" /> | ||
</head> | ||
<body> | ||
<div id="top"><!-- do not remove this div, it is closed by doxygen! --> | ||
<div id="titlearea"> | ||
<table cellspacing="0" cellpadding="0"> | ||
<tbody> | ||
<tr id="projectrow"> | ||
<td id="projectlogo"><img alt="Logo" src="beman-logo.png"/></td> | ||
<td id="projectalign"> | ||
<div id="projectname">beman::execution26 | ||
</div> | ||
<div id="projectbrief">Building Block For Asynchronous Programs</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<!-- end header part --> | ||
<!-- Generated by Doxygen 1.9.6 --> | ||
<script type="text/javascript"> | ||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ | ||
var searchBox = new SearchBox("searchBox", "search/",'.html'); | ||
/* @license-end */ | ||
</script> | ||
<script type="text/javascript" src="menudata.js"></script> | ||
<script type="text/javascript" src="menu.js"></script> | ||
<script type="text/javascript"> | ||
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ | ||
$(function() { | ||
initMenu('',true,false,'search.php','Search'); | ||
$(document).ready(function() { init_search(); }); | ||
}); | ||
/* @license-end */ | ||
</script> | ||
<div id="main-nav"></div> | ||
<!-- window showing the filter options --> | ||
<div id="MSearchSelectWindow" | ||
onmouseover="return searchBox.OnSearchSelectShow()" | ||
onmouseout="return searchBox.OnSearchSelectHide()" | ||
onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
</div> | ||
|
||
<!-- iframe showing the search results (closed by default) --> | ||
<div id="MSearchResultsWindow"> | ||
<div id="MSearchResults"> | ||
<div class="SRPage"> | ||
<div id="SRIndex"> | ||
<div id="SRResults"></div> | ||
<div class="SRStatus" id="Loading">Loading...</div> | ||
<div class="SRStatus" id="Searching">Searching...</div> | ||
<div class="SRStatus" id="NoMatches">No Matches</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div><!-- top --> | ||
<div><div class="header"> | ||
<div class="headertitle"><div class="title">intro-examples </div></div> | ||
</div><!--header--> | ||
<div class="contents"> | ||
<div class="textblock"><h1><a class="anchor" id="autotoc_md0"></a> | ||
Introduction by Example</h1> | ||
<p>This page provides a series of examples showing how to use the <code>std::execution</code> components.</p> | ||
<details > | ||
<summary > | ||
<code>"Hello, world"</code> - synchronous using asynchronous components</summary> | ||
<p></p> | ||
<p>Code: [<code>examples/intro-1-hello-world.cpp</code>]()</p> | ||
<p>The first example is a very complicated way to a version of <code>"Hello, | ||
world"</code>: it uses components for dealing with asynchronous work to synchronously produce the result. The intention is to show a basic use of some involved components to build up a feeling of how things work.</p> | ||
<p>The componentes for <code>std::execution</code> are declared in the header <code><execution></code>. This particular implementation implements the cmponents in namespace <code><a class="el" href="namespacebeman_1_1execution26.html" title="Namespace for asynchronous operations and their vocabulary.">beman::execution26</a></code> declared in the header <code><<a class="el" href="execution_8hpp_source.html">beman/execution26/execution.hpp</a>></code>:</p> | ||
<div class="fragment"><div class="line"> {c++}</div> | ||
<div class="line">#include <beman/execution26/execution.hpp></div> | ||
<div class="line">#include <iostream></div> | ||
<div class="line">#include <string></div> | ||
<div class="line">#include <tuple></div> | ||
<div class="line"> </div> | ||
<div class="line">namespace ex = ::beman::execution26;</div> | ||
<div class="line">using namespace std::string_literals;</div> | ||
</div><!-- fragment --><p>Most of these declarations should be familiar. The namespace alias <code>ex</code> is used to support easy migration to a different implementation, in particular the standard name <code>std::execution</code> once it becomes available with standard library implementations. The other examples will have a similar start which is only mentioned in the explanation to point out unusual parts like the use of custom components.</p> | ||
<p>All interesting work happens in the <code>main</code> function:</p> | ||
<div class="fragment"><div class="line"> {c++}</div> | ||
<div class="line">int main()</div> | ||
<div class="line">{</div> | ||
<div class="line"> auto[result] = ex::sync_wait(</div> | ||
<div class="line"> ex::when_all(</div> | ||
<div class="line"> ex::just("hello, "s),</div> | ||
<div class="line"> ex::just("world"s)</div> | ||
<div class="line"> )</div> | ||
<div class="line"> | ex::then([](auto s1, auto s2){ return s1 + s2; })</div> | ||
<div class="line"> ).value_or(std::tuple(""s));</div> | ||
<div class="line"> </div> | ||
<div class="line"> std::cout << result << '\n';</div> | ||
<div class="line">}</div> | ||
</div><!-- fragment --><p>This code code be simpler even when using components from <code>std::execution</code>. Showing a few more components is intended to better reflect how an asynchronous program might look like. This examples uses a <em>sender factory</em> (<code>ex::just</code>), two <em>sender adaptors</em> (<code>ex::when_all</code> and <code>ex::then</code>), and finally a <em>sender consumer</em> (<code>ex::sync_wait</code>) to build up work and to execute it. The idea of a <em>sender</em> is that it represents work which can be composed with algorithms into a unit of work which is eventually executed.</p> | ||
<p>Each work item can complete asynchronously at some later time, i.e., calling it like a function and using a returned value isn't really an option. Instead, when the work is started it does whatever is needed to get the work completed and get a <em>completion signal</em> delivered. Delivering a completion signal consists of calling a function on a suitable objects. The important part is that once work is started it always delivers exactly one completion signal which can indicate success, failure, or cancellation. Later examples for creating senders will go into more details about the cancellation signals.</p> | ||
<p>The components used in this example do all of that synchronously:</p> | ||
<ul> | ||
<li><code>ex::just("string"s)</code> completes immediately when started with successful completion which includes the string passed as argument.</li> | ||
<li><code>ex::when_all(<em>sender1</em>, <em>sender2</em>)</code> starts the senders passed as arguments. When all of the senders complete, it produces its own completion. In the case of success all the received values are passed to the completion signal. In case of an error all outstanding work is cancelled and the first error becomes <code>when_all</code>'s completion signal once all children have completed. Similarly, in case of cancellation all children get cancelled and once all complete <code>when_all</code> produces a cancellation signal. In the example the two children each produces one string as completion signal and <code>when_all</code> produces these two strings as its completion signal.</li> | ||
<li><code><em>sender</em> | ex::then(<em>fun</em>)</code> is equivalent to using <code>ex::then(<em>sender</em>, <em>fun</em>)</code>. The <code>ex::then</code> calls the function <code><em>fun</em></code> with its child sender completes successful. The arguments to <code><em>fun</em></code> are the values received from the child completion signal. In the example, the child is <code>when_all(...)</code> and it produces two strings which are passed to <code><em>fun</em></code>. The completion signal of <code>ex::then</code> is successful with the value returned from the call to <code><em>fun</em></code> (which may <code>void</code>) if the call returns normally. If an exception is thrown <code>ex::then</code> completes with an <code>std::exception_ptr</code> to the exception thrown. In the example the completion is just a concatenation of the two strings.</li> | ||
<li><code>sync_wait(<em>sender</em>)</code> starts its argument and then blocks until the work completes although the thread calling <code>sync_wait</code> may contribute to the completion of the work. The function returns a an <code>std::optional<std::tuple<<em>results</em>...>></code>>. If the child sender completes successfully the values from the child's completion signal become the elements of the tuple. If the child completes with an error, the error is thrown as an exception. Otherwise, if the work gets cancelled, an empty <code>std::optional<...></code> is returned. In the example, the child sends a string which gets wrapped into a <code>std::tuple</code> which in turn gets wrapped into an <code>std::optional</code>. Thus, the somewhat round-about way to get the result: first using <code>value_or(std::tuple(""s))</code> to get the value from the <code>std::optional</code> which is then decomposed from the <code>std::tuple</code> using structured bindings.</li> | ||
</ul> | ||
<p></p> | ||
</details> | ||
<details > | ||
<summary > | ||
<code>"Hello, async"</code> - a simple asynchronous example</summary> | ||
<p></p> | ||
<p>Code: [<code>examples/intro-2-hello-async.cpp</code>]()</p> | ||
<p></p> | ||
</details> | ||
</div></div><!-- contents --> | ||
</div><!-- PageDoc --> | ||
<!-- start footer part --> | ||
<hr class="footer"/><address class="footer"><small> | ||
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 | ||
</small></address> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var searchData= | ||
[ | ||
['overview_0',['overview',['../md_docs_overview.html',1,'']]] | ||
['intro_2dexamples_0',['intro-examples',['../md_docs_intro_examples.html',1,'']]] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var searchData= | ||
[ | ||
['questions_0',['Questions',['../md_docs_questions.html',1,'']]] | ||
['overview_0',['overview',['../md_docs_overview.html',1,'']]] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var searchData= | ||
[ | ||
['todo_0',['ToDo',['../md_docs_TODO.html',1,'']]] | ||
['questions_0',['Questions',['../md_docs_questions.html',1,'']]] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var searchData= | ||
[ | ||
['todo_0',['ToDo',['../md_docs_TODO.html',1,'']]] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ var indexSectionsWithContent = | |
3: "a", | ||
4: "cfjs", | ||
5: "cef", | ||
6: "aoqt", | ||
6: "aioqt", | ||
7: "b" | ||
}; | ||
|
||
|
Oops, something went wrong.