Auto Generated Documentation

This commit is contained in:
github-actions[bot]
2021-03-14 20:06:11 +00:00
parent fcf47cbac9
commit 799a22692f
11450 changed files with 65837 additions and 83717 deletions
+13 -14
View File
@@ -1,13 +1,13 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Asynchronous green-threads."><meta name="keywords" content="rust, rustlang, rust-lang, task"><title>tokio::task - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `task` mod in crate `tokio`."><meta name="keywords" content="rust, rustlang, rust-lang, task"><title>tokio::task - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../tokio/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module task</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">tokio</a></p><div id="sidebar-vars" data-name="task" data-ty="mod" data-relpath="../"></div><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">tokio</a>::<wbr><a class="mod" href="">task</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../../src/tokio/task/mod.rs.html#1-297" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Asynchronous green-threads.</p>
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../tokio/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module task</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"><a href="../index.html">tokio</a></p><script>window.sidebarCurrent = {name: "task", ty: "mod", relpath: "../"};</script><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../../src/tokio/task/mod.rs.html#1-297" title="goto source code">[src]</a></span><span class="in-band">Module <a href="../index.html">tokio</a>::<wbr><a class="mod" href="">task</a></span></h1><div class="docblock"><p>Asynchronous green-threads.</p>
<h2 id="what-are-tasks" class="section-header"><a href="#what-are-tasks">What are Tasks?</a></h2>
<p>A <em>task</em> is a light weight, non-blocking unit of execution. A task is similar
to an OS thread, but rather than being managed by the OS scheduler, they are
managed by the <a href="../../tokio/runtime/index.html">Tokio runtime</a>. Another name for this general pattern is
<a href="https://en.wikipedia.org/wiki/Green_threads">green threads</a>. If you are familiar with <a href="https://tour.golang.org/concurrency/1">Gos goroutines</a>, <a href="https://kotlinlang.org/docs/reference/coroutines-overview.html">Kotlins
coroutines</a>, or <a href="http://erlang.org/doc/getting_started/conc_prog.html#processes">Erlangs processes</a>, you can think of Tokios tasks as
<a href="https://en.wikipedia.org/wiki/Green_threads">green threads</a>. If you are familiar with <a href="https://tour.golang.org/concurrency/1">Go's goroutines</a>, <a href="https://kotlinlang.org/docs/reference/coroutines-overview.html">Kotlin's
coroutines</a>, or <a href="http://erlang.org/doc/getting_started/conc_prog.html#processes">Erlang's processes</a>, you can think of Tokio's tasks as
something similar.</p>
<p>Key points about tasks include:</p>
<ul>
@@ -25,7 +25,7 @@ operating system allows each thread to run for a period of time, and then
<em>preempts</em> it, temporarily pausing that thread and switching to another.
Tasks, on the other hand, implement <em>cooperative multitasking</em>. In
cooperative multitasking, a task is allowed to run until it <em>yields</em>,
indicating to the Tokio runtimes scheduler that it cannot currently
indicating to the Tokio runtime's scheduler that it cannot currently
continue executing. When a task yields, the Tokio runtime switches to
executing the next task.</p>
</li>
@@ -44,7 +44,7 @@ running blocking operations in an asynchronous context.</p>
<p>This module provides the following APIs for working with tasks:</p>
<h3 id="spawning" class="section-header"><a href="#spawning">Spawning</a></h3>
<p>Perhaps the most important function in this module is <a href="../../tokio/task/fn.spawn.html"><code>task::spawn</code></a>. This
function can be thought of as an async equivalent to the standard librarys
function can be thought of as an async equivalent to the standard library's
<a href="https://doc.rust-lang.org/nightly/std/thread/fn.spawn.html"><code>thread::spawn</code></a>. It takes an <code>async</code> block or other
<a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html">future</a>, and creates a new task to run that work concurrently:</p>
@@ -71,7 +71,7 @@ the spawned task. For example:</p>
<span class="comment">// Await the result of the spawned task.</span>
<span class="kw">let</span> <span class="ident">result</span> <span class="op">=</span> <span class="ident">join</span>.<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">result</span>, <span class="string">&quot;hello world!&quot;</span>);</pre></div>
<p>Again, like <code>std::thread</code>s <a href="https://doc.rust-lang.org/nightly/std/thread/struct.JoinHandle.html"><code>JoinHandle</code> type</a>, if the spawned
<p>Again, like <code>std::thread</code>'s <a href="https://doc.rust-lang.org/nightly/std/thread/struct.JoinHandle.html"><code>JoinHandle</code> type</a>, if the spawned
task panics, awaiting its <code>JoinHandle</code> will return a <a href="../../tokio/task/struct.JoinError.html"><code>JoinError</code></a>`. For
example:</p>
@@ -84,7 +84,7 @@ example:</p>
<span class="comment">// The returned result indicates that the task failed.</span>
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">join</span>.<span class="kw">await</span>.<span class="ident">is_err</span>());</pre></div>
<p><code>spawn</code>, <code>JoinHandle</code>, and <code>JoinError</code> are present when the “rt”
<p><code>spawn</code>, <code>JoinHandle</code>, and <code>JoinError</code> are present when the &quot;rt&quot;
feature flag is enabled.</p>
<h3 id="blocking-and-yielding" class="section-header"><a href="#blocking-and-yielding">Blocking and Yielding</a></h3>
<p>As we discussed above, code running in asynchronous tasks should not perform
@@ -138,9 +138,9 @@ context switches.</p>
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">result</span>, <span class="string">&quot;blocking completed&quot;</span>);</pre></div>
<h4 id="yield_now" class="section-header"><a href="#yield_now">yield_now</a></h4>
<p>In addition, this module provides a <a href="../../tokio/task/fn.yield_now.html"><code>task::yield_now</code></a> async function
that is analogous to the standard librarys <a href="https://doc.rust-lang.org/nightly/std/thread/fn.yield_now.html"><code>thread::yield_now</code></a>. Calling
that is analogous to the standard library's <a href="https://doc.rust-lang.org/nightly/std/thread/fn.yield_now.html"><code>thread::yield_now</code></a>. Calling
and <code>await</code>ing this function will cause the current task to yield to the
Tokio runtimes scheduler, allowing other tasks to be
Tokio runtime's scheduler, allowing other tasks to be
scheduled. Eventually, the yielding task will be polled again, allowing it
to execute. For example:</p>
@@ -177,7 +177,7 @@ yield, and will starve other tasks and resources on the same executor.</p>
<p>To account for this, Tokio has explicit yield points in a number of library
functions, which force tasks to return to the executor periodically.</p>
<h4 id="unconstrained" class="section-header"><a href="#unconstrained">unconstrained</a></h4>
<p>If necessary, <a href="../../tokio/task/fn.unconstrained.html"><code>task::unconstrained</code></a> lets you opt out a future of Tokios cooperative
<p>If necessary, <a href="../../tokio/task/fn.unconstrained.html"><code>task::unconstrained</code></a> lets you opt out a future of Tokio's cooperative
scheduling. When a future is wrapped with <code>unconstrained</code>, it will never be forced to yield to
Tokio. For example:</p>
@@ -213,5 +213,4 @@ blocking the executor.</p>
Tokio. Using this exposes your service to starvation if the unconstrained future never yields
otherwise.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.yield_now.html" title="tokio::task::yield_now fn">yield_now</a></td><td class="docblock-short"><p>Yields execution back to the Tokio runtime.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="tokio"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../../";window.currentCrate = "tokio";</script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>