Files
google-apis-rs/futures/executor/index.html
2021-04-02 00:20:57 +08:00

43 lines
8.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 `executor` mod in crate `futures`."><meta name="keywords" content="rust, rustlang, rust-lang, executor"><title>futures::executor - 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='../../futures/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module executor</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">futures</a></p><div id="sidebar-vars" data-name="executor" 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">futures</a>::<wbr><a class="mod" href="">executor</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/futures_executor/lib.rs.html#1-69" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Built-in executors and related tools.</p>
<p>All asynchronous computation occurs within an executor, which is
capable of spawning futures as tasks. This module provides several
built-in executors, as well as tools for building your own.</p>
<p>All items are only available when the <code>std</code> feature of this
library is activated, and it is activated by default.</p>
<h1 id="using-a-thread-pool-mn-task-scheduling" class="section-header"><a href="#using-a-thread-pool-mn-task-scheduling">Using a thread pool (M:N task scheduling)</a></h1>
<p>Most of the time tasks should be executed on a <a href="ThreadPool">thread pool</a>.
A small set of worker threads can handle a very large set of spawned tasks
(which are much lighter weight than threads). Tasks spawned onto the pool
with the <a href="ThreadPool::spawn_ok"><code>spawn_ok</code></a> function will run ambiently on
the created threads.</p>
<h1 id="spawning-additional-tasks" class="section-header"><a href="#spawning-additional-tasks">Spawning additional tasks</a></h1>
<p>Tasks can be spawned onto a spawner by calling its <a href="https://docs.rs/futures/0.3/futures/task/trait.Spawn.html#tymethod.spawn_obj"><code>spawn_obj</code></a> method
directly. In the case of <code>!Send</code> futures, <a href="https://docs.rs/futures/0.3/futures/task/trait.LocalSpawn.html#tymethod.spawn_local_obj"><code>spawn_local_obj</code></a> can be used
instead.</p>
<h1 id="single-threaded-execution" class="section-header"><a href="#single-threaded-execution">Single-threaded execution</a></h1>
<p>In addition to thread pools, it's possible to run a task (and the tasks
it spawns) entirely within a single thread via the <a href="../../futures/executor/struct.LocalPool.html" title="LocalPool"><code>LocalPool</code></a> executor.
Aside from cutting down on synchronization costs, this executor also makes
it possible to spawn non-<code>Send</code> tasks, via <a href="https://docs.rs/futures/0.3/futures/task/trait.LocalSpawn.html#tymethod.spawn_local_obj"><code>spawn_local_obj</code></a>. The
<a href="../../futures/executor/struct.LocalPool.html" title="LocalPool"><code>LocalPool</code></a> is best suited for running I/O-bound tasks that do relatively
little work between I/O operations.</p>
<p>There is also a convenience function <a href="../../futures/executor/fn.block_on.html" title="block_on"><code>block_on</code></a> for simply running a
future to completion on the current thread.</p>
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
<table><tr class="module-item"><td><a class="struct" href="struct.BlockingStream.html" title="futures::executor::BlockingStream struct">BlockingStream</a></td><td class="docblock-short"><p>An iterator which blocks on values from a stream until they become available.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Enter.html" title="futures::executor::Enter struct">Enter</a></td><td class="docblock-short"><p>Represents an executor context.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.EnterError.html" title="futures::executor::EnterError struct">EnterError</a></td><td class="docblock-short"><p>An error returned by <code>enter</code> if an execution scope has already been
entered.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.LocalPool.html" title="futures::executor::LocalPool struct">LocalPool</a></td><td class="docblock-short"><p>A single-threaded task pool for polling futures to completion.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.LocalSpawner.html" title="futures::executor::LocalSpawner struct">LocalSpawner</a></td><td class="docblock-short"><p>A handle to a <a href="../../futures/executor/struct.LocalPool.html"><code>LocalPool</code></a> that implements
<a href="../../futures/task/trait.Spawn.html"><code>Spawn</code></a>.</p>
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
<table><tr class="module-item"><td><a class="fn" href="fn.block_on.html" title="futures::executor::block_on fn">block_on</a></td><td class="docblock-short"><p>Run a future to completion on the current thread.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.block_on_stream.html" title="futures::executor::block_on_stream fn">block_on_stream</a></td><td class="docblock-short"><p>Turn a stream into a blocking iterator.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.enter.html" title="futures::executor::enter fn">enter</a></td><td class="docblock-short"><p>Marks the current thread as being within the dynamic extent of an
executor.</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="futures"></div>
<script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>