28 lines
7.7 KiB
HTML
28 lines
7.7 KiB
HTML
<!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="Built-in executors and related tools."><title>futures_executor - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="futures_executor" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Crate futures_executor</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../futures_executor/index.html">futures_<wbr>executor</a><span class="version">0.3.32</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#using-a-thread-pool-mn-task-scheduling" title="Using a thread pool (M:N task scheduling)">Using a thread pool (M:N task scheduling)</a></li><li><a href="#spawning-additional-tasks" title="Spawning additional tasks">Spawning additional tasks</a></li><li><a href="#single-threaded-execution" title="Single-threaded execution">Single-threaded execution</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>futures_<wbr>executor</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/futures_executor/lib.rs.html#1-73">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><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>
|
||
<h2 id="using-a-thread-pool-mn-task-scheduling"><a class="doc-anchor" href="#using-a-thread-pool-mn-task-scheduling">§</a>Using a thread pool (M:N task scheduling)</h2>
|
||
<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>
|
||
<h2 id="spawning-additional-tasks"><a class="doc-anchor" href="#spawning-additional-tasks">§</a>Spawning additional tasks</h2>
|
||
<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>
|
||
<h2 id="single-threaded-execution"><a class="doc-anchor" href="#single-threaded-execution">§</a>Single-threaded execution</h2>
|
||
<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="struct.LocalPool.html" title="struct futures_executor::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="struct.LocalPool.html" title="struct futures_executor::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="fn.block_on.html" title="fn futures_executor::block_on"><code>block_on</code></a> for simply running a
|
||
future to completion on the current thread.</p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.BlockingStream.html" title="struct futures_executor::BlockingStream">Blocking<wbr>Stream</a></dt><dd>An iterator which blocks on values from a stream until they become available.</dd><dt><a class="struct" href="struct.Enter.html" title="struct futures_executor::Enter">Enter</a></dt><dd>Represents an executor context.</dd><dt><a class="struct" href="struct.EnterError.html" title="struct futures_executor::EnterError">Enter<wbr>Error</a></dt><dd>An error returned by <code>enter</code> if an execution scope has already been
|
||
entered.</dd><dt><a class="struct" href="struct.LocalPool.html" title="struct futures_executor::LocalPool">Local<wbr>Pool</a></dt><dd>A single-threaded task pool for polling futures to completion.</dd><dt><a class="struct" href="struct.LocalSpawner.html" title="struct futures_executor::LocalSpawner">Local<wbr>Spawner</a></dt><dd>A handle to a <a href="struct.LocalPool.html" title="struct futures_executor::LocalPool"><code>LocalPool</code></a> that implements <a href="../futures_task/spawn/trait.Spawn.html" title="trait futures_task::spawn::Spawn"><code>Spawn</code></a>.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.block_on.html" title="fn futures_executor::block_on">block_<wbr>on</a></dt><dd>Run a future to completion on the current thread.</dd><dt><a class="fn" href="fn.block_on_stream.html" title="fn futures_executor::block_on_stream">block_<wbr>on_<wbr>stream</a></dt><dd>Turn a stream into a blocking iterator.</dd><dt><a class="fn" href="fn.enter.html" title="fn futures_executor::enter">enter</a></dt><dd>Marks the current thread as being within the dynamic extent of an
|
||
executor.</dd></dl></section></div></main></body></html> |