mirror of
https://github.com/fafhrd91/actix-net
synced 2025-07-02 20:04:31 +02:00
Deploying to gh-pages from @ actix/actix-net@af00dada5c 🚀
This commit is contained in:
1
actix_rt/all.html
Normal file
1
actix_rt/all.html
Normal file
File diff suppressed because one or more lines are too long
11
actix_rt/arbiter/struct.Arbiter.html
Normal file
11
actix_rt/arbiter/struct.Arbiter.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../actix_rt/struct.Arbiter.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../actix_rt/struct.Arbiter.html">../../actix_rt/struct.Arbiter.html</a>...</p>
|
||||
<script>location.replace("../../actix_rt/struct.Arbiter.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
11
actix_rt/arbiter/struct.ArbiterHandle.html
Normal file
11
actix_rt/arbiter/struct.ArbiterHandle.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../actix_rt/struct.ArbiterHandle.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../actix_rt/struct.ArbiterHandle.html">../../actix_rt/struct.ArbiterHandle.html</a>...</p>
|
||||
<script>location.replace("../../actix_rt/struct.ArbiterHandle.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
7
actix_rt/attr.main.html
Normal file
7
actix_rt/attr.main.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!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="Marks async entry-point function to be executed by Actix system."><title>main in actix_rt - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc attr"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">main</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">actix_rt</a></span><h1>Attribute Macro <span class="attr">main</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>#[main]</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Marks async entry-point function to be executed by Actix system.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[actix_rt::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"Hello world"</span>);
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
7
actix_rt/attr.test.html
Normal file
7
actix_rt/attr.test.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!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="Marks async test function to be executed in an Actix system."><title>test in actix_rt - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc attr"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">test</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">actix_rt</a></span><h1>Attribute Macro <span class="attr">test</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>#[test]</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Marks async test function to be executed in an Actix system.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#[actix_rt::test]
|
||||
</span><span class="kw">async fn </span>my_test() {
|
||||
<span class="macro">assert!</span>(<span class="bool-val">true</span>);
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
24
actix_rt/fn.spawn.html
Normal file
24
actix_rt/fn.spawn.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!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="Spawns a future on the current thread as a new task."><title>spawn in actix_rt - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">spawn</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">actix_rt</a></span><h1>Function <span class="fn">spawn</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/actix_rt/lib.rs.html#203-209">source</a> </span></div><pre class="rust item-decl"><code>pub fn spawn<Fut>(f: Fut) -> <a class="struct" href="task/struct.JoinHandle.html" title="struct actix_rt::task::JoinHandle">JoinHandle</a><Fut::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>> <a href="#" class="tooltip" data-notable-ty="JoinHandle<Fut::Output>">ⓘ</a><div class="where">where
|
||||
Fut: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future">Future</a> + 'static,
|
||||
Fut::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output" title="type core::future::future::Future::Output">Output</a>: 'static,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Spawns a future on the current thread as a new task.</p>
|
||||
<p>If not immediately awaited, the task can be cancelled using <a href="task/struct.JoinHandle.html#method.abort" title="method actix_rt::task::JoinHandle::abort"><code>JoinHandle::abort</code></a>.</p>
|
||||
<p>The provided future is spawned as a new task; therefore, panics are caught.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>Panics if Actix system is not running.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// task resolves successfully
|
||||
</span><span class="macro">assert_eq!</span>(actix_rt::spawn(<span class="kw">async </span>{ <span class="number">1 </span>}).<span class="kw">await</span>.unwrap(), <span class="number">1</span>);
|
||||
|
||||
<span class="comment">// task panics
|
||||
</span><span class="macro">assert!</span>(actix_rt::spawn(<span class="kw">async </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"panic is caught at task boundary"</span>);
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>.unwrap_err()
|
||||
.is_panic());
|
||||
|
||||
<span class="comment">// task is cancelled before completion
|
||||
</span><span class="kw">let </span>handle = actix_rt::spawn(actix_rt::time::sleep(Duration::from_secs(<span class="number">100</span>)));
|
||||
handle.abort();
|
||||
<span class="macro">assert!</span>(handle.<span class="kw">await</span>.unwrap_err().is_cancelled());</code></pre></div>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"JoinHandle<Fut::Output>":"<h3>Notable traits for <code><a class=\"struct\" href=\"task/struct.JoinHandle.html\" title=\"struct actix_rt::task::JoinHandle\">JoinHandle</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"task/struct.JoinHandle.html\" title=\"struct actix_rt::task::JoinHandle\">JoinHandle</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"enum\" href=\"https://doc.rust-lang.org/nightly/core/result/enum.Result.html\" title=\"enum core::result::Result\">Result</a><T, <a class=\"struct\" href=\"task/struct.JoinError.html\" title=\"struct actix_rt::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
35
actix_rt/index.html
Normal file
35
actix_rt/index.html
Normal file
@ -0,0 +1,35 @@
|
||||
<!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="Tokio-based single-threaded async runtime for the Actix ecosystem."><title>actix_rt - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</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="#examples" title="Examples">Examples</a></li><li><a href="#io-uring-support" title="`io-uring` Support"><code>io-uring</code> Support</a></li></ul><h3><a href="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#attributes" title="Attribute Macros">Attribute Macros</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>actix_rt</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/actix_rt/lib.rs.html#1-209">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Tokio-based single-threaded async runtime for the Actix ecosystem.</p>
|
||||
<p>In most parts of the the Actix ecosystem, it has been chosen to use !Send futures. For this
|
||||
reason, a single-threaded runtime is appropriate since it is guaranteed that futures will not
|
||||
be moved between threads. This can result in small performance improvements over cases where
|
||||
atomics would otherwise be needed.</p>
|
||||
<p>To achieve similar performance to multi-threaded, work-stealing runtimes, applications
|
||||
using <code>actix-rt</code> will create multiple, mostly disconnected, single-threaded runtimes.
|
||||
This approach has good performance characteristics for workloads where the majority of tasks
|
||||
have similar runtime expense.</p>
|
||||
<p>The disadvantage is that idle threads will not steal work from very busy, stuck or otherwise
|
||||
backlogged threads. Tasks that are disproportionately expensive should be offloaded to the
|
||||
blocking task thread-pool using <a href="task/fn.spawn_blocking.html" title="fn actix_rt::task::spawn_blocking"><code>task::spawn_blocking</code></a>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::sync::mpsc;
|
||||
<span class="kw">use </span>actix_rt::{Arbiter, System};
|
||||
|
||||
<span class="kw">let _ </span>= System::new();
|
||||
|
||||
<span class="kw">let </span>(tx, rx) = mpsc::channel::<u32>();
|
||||
|
||||
<span class="kw">let </span>arbiter = Arbiter::new();
|
||||
arbiter.spawn_fn(<span class="kw">move </span>|| tx.send(<span class="number">42</span>).unwrap());
|
||||
|
||||
<span class="kw">let </span>num = rx.recv().unwrap();
|
||||
<span class="macro">assert_eq!</span>(num, <span class="number">42</span>);
|
||||
|
||||
arbiter.stop();
|
||||
arbiter.join().unwrap();</code></pre></div>
|
||||
<h2 id="io-uring-support"><a class="doc-anchor" href="#io-uring-support">§</a><code>io-uring</code> Support</h2>
|
||||
<p>There is experimental support for using io-uring with this crate by enabling the
|
||||
<code>io-uring</code> feature. For now, it is semver exempt.</p>
|
||||
<p>Note that there are currently some unimplemented parts of using <code>actix-rt</code> with <code>io-uring</code>.
|
||||
In particular, when running a <code>System</code>, only <code>System::block_on</code> is supported.</p>
|
||||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="net/index.html" title="mod actix_rt::net">net</a></div><div class="desc docblock-short">TCP/UDP/Unix bindings (mostly Tokio re-exports).</div></li><li><div class="item-name"><a class="mod" href="signal/index.html" title="mod actix_rt::signal">signal</a></div><div class="desc docblock-short">Asynchronous signal handling (Tokio re-exports).</div></li><li><div class="item-name"><a class="mod" href="task/index.html" title="mod actix_rt::task">task</a></div><div class="desc docblock-short">Task management (Tokio re-exports).</div></li><li><div class="item-name"><a class="mod" href="time/index.html" title="mod actix_rt::time">time</a></div><div class="desc docblock-short">Utilities for tracking time (Tokio re-exports).</div></li></ul><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.pin.html" title="macro actix_rt::pin">pin</a></div><div class="desc docblock-short">Pins a value on the stack.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Arbiter.html" title="struct actix_rt::Arbiter">Arbiter</a></div><div class="desc docblock-short">An Arbiter represents a thread that provides an asynchronous execution environment for futures
|
||||
and functions.</div></li><li><div class="item-name"><a class="struct" href="struct.ArbiterHandle.html" title="struct actix_rt::ArbiterHandle">Arbiter<wbr>Handle</a></div><div class="desc docblock-short">A handle for sending spawn and stop messages to an <a href="struct.Arbiter.html" title="struct actix_rt::Arbiter">Arbiter</a>.</div></li><li><div class="item-name"><a class="struct" href="struct.Runtime.html" title="struct actix_rt::Runtime">Runtime</a></div><div class="desc docblock-short">A Tokio-based runtime proxy.</div></li><li><div class="item-name"><a class="struct" href="struct.System.html" title="struct actix_rt::System">System</a></div><div class="desc docblock-short">A manager for a per-thread distributed async runtime.</div></li><li><div class="item-name"><a class="struct" href="struct.SystemRunner.html" title="struct actix_rt::SystemRunner">System<wbr>Runner</a></div><div class="desc docblock-short">Runner that keeps a <a href="struct.System.html" title="struct actix_rt::System">System</a>’s event loop alive until stop message is received.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.spawn.html" title="fn actix_rt::spawn">spawn</a></div><div class="desc docblock-short">Spawns a future on the current thread as a new task.</div></li></ul><h2 id="attributes" class="section-header">Attribute Macros<a href="#attributes" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="attr" href="attr.main.html" title="attr actix_rt::main">main</a></div><div class="desc docblock-short">Marks async entry-point function to be executed by Actix system.</div></li><li><div class="item-name"><a class="attr" href="attr.test.html" title="attr actix_rt::test">test</a></div><div class="desc docblock-short">Marks async test function to be executed in an Actix system.</div></li></ul></section></div></main></body></html>
|
11
actix_rt/macro.pin!.html
Normal file
11
actix_rt/macro.pin!.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=macro.pin.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="macro.pin.html">macro.pin.html</a>...</p>
|
||||
<script>location.replace("macro.pin.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
104
actix_rt/macro.pin.html
Normal file
104
actix_rt/macro.pin.html
Normal file
@ -0,0 +1,104 @@
|
||||
<!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="Pins a value on the stack."><title>pin in actix_rt - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">pin</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#usage" title="Usage">Usage</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">actix_rt</a></span><h1>Macro <span class="macro">pin</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><span class="macro">macro_rules!</span> pin {
|
||||
($(<span class="macro-nonterminal">$x</span>:ident),<span class="kw-2">*</span>) => { ... };
|
||||
($(
|
||||
<span class="kw">let </span><span class="macro-nonterminal">$x</span>:ident = <span class="macro-nonterminal">$init</span>:expr;
|
||||
)<span class="kw-2">*</span>) => { ... };
|
||||
}</pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Pins a value on the stack.</p>
|
||||
<p>Calls to <code>async fn</code> return anonymous <a href="https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html" title="trait core::future::future::Future"><code>Future</code></a> values that are <code>!Unpin</code>.
|
||||
These values must be pinned before they can be polled. Calling <code>.await</code> will
|
||||
handle this, but consumes the future. If it is required to call <code>.await</code> on
|
||||
a <code>&mut _</code> reference, the caller is responsible for pinning the future.</p>
|
||||
<p>Pinning may be done by allocating with <a href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html#method.pin" title="associated function alloc::boxed::Box::pin"><code>Box::pin</code></a> or by using the stack
|
||||
with the <code>pin!</code> macro.</p>
|
||||
<p>The following will <strong>fail to compile</strong>:</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>my_async_fn() {
|
||||
<span class="comment">// async logic here
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>future = my_async_fn();
|
||||
(<span class="kw-2">&mut </span>future).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
<p>To make this work requires pinning:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::pin;
|
||||
|
||||
<span class="kw">async fn </span>my_async_fn() {
|
||||
<span class="comment">// async logic here
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span>future = my_async_fn();
|
||||
<span class="macro">pin!</span>(future);
|
||||
|
||||
(<span class="kw-2">&mut </span>future).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
<p>Pinning is useful when using <code>select!</code> and stream operators that require <code>T: Stream + Unpin</code>.</p>
|
||||
<h2 id="usage"><a class="doc-anchor" href="#usage">§</a>Usage</h2>
|
||||
<p>The <code>pin!</code> macro takes <strong>identifiers</strong> as arguments. It does <strong>not</strong> work
|
||||
with expressions.</p>
|
||||
<p>The following does not compile as an expression is passed to <code>pin!</code>.</p>
|
||||
|
||||
<div class="example-wrap compile_fail"><a href="#" class="tooltip" title="This example deliberately fails to compile">ⓘ</a><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>my_async_fn() {
|
||||
<span class="comment">// async logic here
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>future = <span class="macro">pin!</span>(my_async_fn());
|
||||
(<span class="kw-2">&mut </span>future).<span class="kw">await</span>;
|
||||
}</code></pre></div>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Using with select:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::{pin, select};
|
||||
<span class="kw">use </span>tokio_stream::{<span class="self">self </span><span class="kw">as </span>stream, StreamExt};
|
||||
|
||||
<span class="kw">async fn </span>my_async_fn() {
|
||||
<span class="comment">// async logic here
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]);
|
||||
|
||||
<span class="kw">let </span>future = my_async_fn();
|
||||
<span class="macro">pin!</span>(future);
|
||||
|
||||
<span class="kw">loop </span>{
|
||||
<span class="macro">select!</span> {
|
||||
<span class="kw">_ </span>= <span class="kw-2">&mut </span>future => {
|
||||
<span class="comment">// Stop looping `future` will be polled after completion
|
||||
</span><span class="kw">break</span>;
|
||||
}
|
||||
<span class="prelude-val">Some</span>(val) = stream.next() => {
|
||||
<span class="macro">println!</span>(<span class="string">"got value = {}"</span>, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}</code></pre></div>
|
||||
<p>Because assigning to a variable followed by pinning is common, there is also
|
||||
a variant of the macro that supports doing both in one go.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::{pin, select};
|
||||
|
||||
<span class="kw">async fn </span>my_async_fn() {
|
||||
<span class="comment">// async logic here
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">pin!</span> {
|
||||
<span class="kw">let </span>future1 = my_async_fn();
|
||||
<span class="kw">let </span>future2 = my_async_fn();
|
||||
}
|
||||
|
||||
<span class="macro">select!</span> {
|
||||
<span class="kw">_ </span>= <span class="kw-2">&mut </span>future1 => {}
|
||||
<span class="kw">_ </span>= <span class="kw-2">&mut </span>future2 => {}
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
3
actix_rt/net/index.html
Normal file
3
actix_rt/net/index.html
Normal file
@ -0,0 +1,3 @@
|
||||
<!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="TCP/UDP/Unix bindings (mostly Tokio re-exports)."><title>actix_rt::net - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module net</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a></span><h1>Module <span>net</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/actix_rt/lib.rs.html#86">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>TCP/UDP/Unix bindings (mostly Tokio re-exports).</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Ready.html" title="struct actix_rt::net::Ready">Ready</a></div><div class="desc docblock-short">Describes the readiness state of an I/O resources.</div></li><li><div class="item-name"><a class="struct" href="struct.TcpListener.html" title="struct actix_rt::net::TcpListener">TcpListener</a></div><div class="desc docblock-short">A TCP socket server, listening for connections.</div></li><li><div class="item-name"><a class="struct" href="struct.TcpSocket.html" title="struct actix_rt::net::TcpSocket">TcpSocket</a></div><div class="desc docblock-short">A TCP socket that has not yet been converted to a <code>TcpStream</code> or
|
||||
<code>TcpListener</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.TcpStream.html" title="struct actix_rt::net::TcpStream">TcpStream</a></div><div class="desc docblock-short">A TCP stream between a local and a remote socket.</div></li><li><div class="item-name"><a class="struct" href="struct.UdpSocket.html" title="struct actix_rt::net::UdpSocket">UdpSocket</a></div><div class="desc docblock-short">A UDP socket.</div></li><li><div class="item-name"><a class="struct" href="struct.UnixDatagram.html" title="struct actix_rt::net::UnixDatagram">Unix<wbr>Datagram</a></div><div class="desc docblock-short">An I/O object representing a Unix datagram socket.</div></li><li><div class="item-name"><a class="struct" href="struct.UnixListener.html" title="struct actix_rt::net::UnixListener">Unix<wbr>Listener</a></div><div class="desc docblock-short">A Unix socket which can accept connections from other Unix sockets.</div></li><li><div class="item-name"><a class="struct" href="struct.UnixStream.html" title="struct actix_rt::net::UnixStream">Unix<wbr>Stream</a></div><div class="desc docblock-short">A structure representing a connected Unix socket.</div></li></ul></section></div></main></body></html>
|
1
actix_rt/net/sidebar-items.js
Normal file
1
actix_rt/net/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"struct":["Ready","TcpListener","TcpSocket","TcpStream","UdpSocket","UnixDatagram","UnixListener","UnixStream"]};
|
80
actix_rt/net/struct.Ready.html
Normal file
80
actix_rt/net/struct.Ready.html
Normal file
File diff suppressed because one or more lines are too long
198
actix_rt/net/struct.TcpListener.html
Normal file
198
actix_rt/net/struct.TcpListener.html
Normal file
File diff suppressed because one or more lines are too long
394
actix_rt/net/struct.TcpSocket.html
Normal file
394
actix_rt/net/struct.TcpSocket.html
Normal file
File diff suppressed because one or more lines are too long
718
actix_rt/net/struct.TcpStream.html
Normal file
718
actix_rt/net/struct.TcpStream.html
Normal file
File diff suppressed because one or more lines are too long
1030
actix_rt/net/struct.UdpSocket.html
Normal file
1030
actix_rt/net/struct.UdpSocket.html
Normal file
File diff suppressed because one or more lines are too long
868
actix_rt/net/struct.UnixDatagram.html
Normal file
868
actix_rt/net/struct.UnixDatagram.html
Normal file
File diff suppressed because one or more lines are too long
90
actix_rt/net/struct.UnixListener.html
Normal file
90
actix_rt/net/struct.UnixListener.html
Normal file
File diff suppressed because one or more lines are too long
575
actix_rt/net/struct.UnixStream.html
Normal file
575
actix_rt/net/struct.UnixStream.html
Normal file
File diff suppressed because one or more lines are too long
11
actix_rt/runtime/struct.Runtime.html
Normal file
11
actix_rt/runtime/struct.Runtime.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../actix_rt/struct.Runtime.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../actix_rt/struct.Runtime.html">../../actix_rt/struct.Runtime.html</a>...</p>
|
||||
<script>location.replace("../../actix_rt/struct.Runtime.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
1
actix_rt/sidebar-items.js
Normal file
1
actix_rt/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"attr":["main","test"],"fn":["spawn"],"macro":["pin"],"mod":["net","signal","task","time"],"struct":["Arbiter","ArbiterHandle","Runtime","System","SystemRunner"]};
|
39
actix_rt/signal/fn.ctrl_c.html
Normal file
39
actix_rt/signal/fn.ctrl_c.html
Normal file
@ -0,0 +1,39 @@
|
||||
<!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="Completes when a “ctrl-c” notification is sent to the process."><title>ctrl_c in actix_rt::signal - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">ctrl_c</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#caveats" title="Caveats">Caveats</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>signal</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">signal</a></span><h1>Function <span class="fn">ctrl_c</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub async fn ctrl_c() -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Completes when a “ctrl-c” notification is sent to the process.</p>
|
||||
<p>While signals are handled very differently between Unix and Windows, both
|
||||
platforms support receiving a signal on “ctrl-c”. This function provides a
|
||||
portable API for receiving this notification.</p>
|
||||
<p>Once the returned future is polled, a listener is registered. The future
|
||||
will complete on the first received <code>ctrl-c</code> <strong>after</strong> the initial call to
|
||||
either <code>Future::poll</code> or <code>.await</code>.</p>
|
||||
<h2 id="caveats"><a class="doc-anchor" href="#caveats">§</a>Caveats</h2>
|
||||
<p>On Unix platforms, the first time that a <code>Signal</code> instance is registered for a
|
||||
particular signal kind, an OS signal-handler is installed which replaces the
|
||||
default platform behavior when that signal is received, <strong>for the duration of
|
||||
the entire process</strong>.</p>
|
||||
<p>For example, Unix systems will terminate a process by default when it
|
||||
receives a signal generated by <code>"CTRL+C"</code> on the terminal. But, when a
|
||||
<code>ctrl_c</code> stream is created to listen for this signal, the time it arrives,
|
||||
it will be translated to a stream event, and the process will continue to
|
||||
execute. <strong>Even if this <code>Signal</code> instance is dropped, subsequent <code>SIGINT</code>
|
||||
deliveries will end up captured by Tokio, and the default platform behavior
|
||||
will NOT be reset</strong>.</p>
|
||||
<p>Thus, applications should take care to ensure the expected signal behavior
|
||||
occurs as expected after listening for specific signals.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::signal;
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="macro">println!</span>(<span class="string">"waiting for ctrl-c"</span>);
|
||||
|
||||
signal::ctrl_c().<span class="kw">await</span>.expect(<span class="string">"failed to listen for event"</span>);
|
||||
|
||||
<span class="macro">println!</span>(<span class="string">"received ctrl-c event"</span>);
|
||||
}</code></pre></div>
|
||||
<p>Listen in the background:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>tokio::spawn(<span class="kw">async move </span>{
|
||||
tokio::signal::ctrl_c().<span class="kw">await</span>.unwrap();
|
||||
<span class="comment">// Your handler here
|
||||
</span>});</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
2
actix_rt/signal/index.html
Normal file
2
actix_rt/signal/index.html
Normal file
@ -0,0 +1,2 @@
|
||||
<!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 signal handling (Tokio re-exports)."><title>actix_rt::signal - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module signal</a></h2><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a></span><h1>Module <span>signal</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/actix_rt/lib.rs.html#75">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Asynchronous signal handling (Tokio re-exports).</p>
|
||||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="unix/index.html" title="mod actix_rt::signal::unix">unix</a></div><div class="desc docblock-short">Unix specific signals (Tokio re-exports).</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.ctrl_c.html" title="fn actix_rt::signal::ctrl_c">ctrl_c</a></div><div class="desc docblock-short">Completes when a “ctrl-c” notification is sent to the process.</div></li></ul></section></div></main></body></html>
|
1
actix_rt/signal/sidebar-items.js
Normal file
1
actix_rt/signal/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["ctrl_c"],"mod":["unix"]};
|
25
actix_rt/signal/unix/fn.signal.html
Normal file
25
actix_rt/signal/unix/fn.signal.html
Normal file
@ -0,0 +1,25 @@
|
||||
<!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="Creates a new listener which will receive notifications when the current process receives the specified signal `kind`."><title>signal in actix_rt::signal::unix - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">signal</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#errors" title="Errors">Errors</a></li><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>signal::<wbr>unix</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">actix_rt</a>::<wbr><a href="../index.html">signal</a>::<wbr><a href="index.html">unix</a></span><h1>Function <span class="fn">signal</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn signal(kind: <a class="struct" href="struct.SignalKind.html" title="struct actix_rt::signal::unix::SignalKind">SignalKind</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="struct.Signal.html" title="struct actix_rt::signal::unix::Signal">Signal</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html" title="struct std::io::error::Error">Error</a>></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a new listener which will receive notifications when the current
|
||||
process receives the specified signal <code>kind</code>.</p>
|
||||
<p>This function will create a new stream which binds to the default reactor.
|
||||
The <code>Signal</code> stream is an infinite stream which will receive
|
||||
notifications whenever a signal is received. More documentation can be
|
||||
found on <code>Signal</code> itself, but to reiterate:</p>
|
||||
<ul>
|
||||
<li>Signals may be coalesced beyond what the kernel already does.</li>
|
||||
<li>Once a signal handler is registered with the process the underlying
|
||||
libc signal handler is never unregistered.</li>
|
||||
</ul>
|
||||
<p>A <code>Signal</code> stream can be created for a particular signal number
|
||||
multiple times. When a signal is received then all the associated
|
||||
channels will receive the signal notification.</p>
|
||||
<h2 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h2>
|
||||
<ul>
|
||||
<li>If the lower-level C functions fail for some reason.</li>
|
||||
<li>If the previous initialization of this specific signal failed.</li>
|
||||
<li>If the signal is one of
|
||||
<a href="fn@signal_hook_registry::register#panics"><code>signal_hook::FORBIDDEN</code></a></li>
|
||||
</ul>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if there is no current reactor set, or if the <code>rt</code>
|
||||
feature flag is not enabled.</p>
|
||||
</div></details></section></div></main></body></html>
|
3
actix_rt/signal/unix/index.html
Normal file
3
actix_rt/signal/unix/index.html
Normal file
@ -0,0 +1,3 @@
|
||||
<!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="Unix specific signals (Tokio re-exports)."><title>actix_rt::signal::unix - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module unix</a></h2><h3><a href="#structs">Module 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"><h2><a href="../index.html">In actix_<wbr>rt::<wbr>signal</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">actix_rt</a>::<wbr><a href="../index.html">signal</a></span><h1>Module <span>unix</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/actix_rt/lib.rs.html#79">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Unix specific signals (Tokio re-exports).</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Signal.html" title="struct actix_rt::signal::unix::Signal">Signal</a></div><div class="desc docblock-short">An listener for receiving a particular type of OS signal.</div></li><li><div class="item-name"><a class="struct" href="struct.SignalKind.html" title="struct actix_rt::signal::unix::SignalKind">Signal<wbr>Kind</a></div><div class="desc docblock-short">Represents the specific kind of signal to listen for.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.signal.html" title="fn actix_rt::signal::unix::signal">signal</a></div><div class="desc docblock-short">Creates a new listener which will receive notifications when the current
|
||||
process receives the specified signal <code>kind</code>.</div></li></ul></section></div></main></body></html>
|
1
actix_rt/signal/unix/sidebar-items.js
Normal file
1
actix_rt/signal/unix/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["signal"],"struct":["Signal","SignalKind"]};
|
119
actix_rt/signal/unix/struct.Signal.html
Normal file
119
actix_rt/signal/unix/struct.Signal.html
Normal file
File diff suppressed because one or more lines are too long
63
actix_rt/signal/unix/struct.SignalKind.html
Normal file
63
actix_rt/signal/unix/struct.SignalKind.html
Normal file
File diff suppressed because one or more lines are too long
37
actix_rt/struct.Arbiter.html
Normal file
37
actix_rt/struct.Arbiter.html
Normal file
File diff suppressed because one or more lines are too long
26
actix_rt/struct.ArbiterHandle.html
Normal file
26
actix_rt/struct.ArbiterHandle.html
Normal file
File diff suppressed because one or more lines are too long
85
actix_rt/struct.Runtime.html
Normal file
85
actix_rt/struct.Runtime.html
Normal file
File diff suppressed because one or more lines are too long
29
actix_rt/struct.System.html
Normal file
29
actix_rt/struct.System.html
Normal file
File diff suppressed because one or more lines are too long
15
actix_rt/struct.SystemRunner.html
Normal file
15
actix_rt/struct.SystemRunner.html
Normal file
File diff suppressed because one or more lines are too long
11
actix_rt/system/struct.System.html
Normal file
11
actix_rt/system/struct.System.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../actix_rt/struct.System.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../actix_rt/struct.System.html">../../actix_rt/struct.System.html</a>...</p>
|
||||
<script>location.replace("../../actix_rt/struct.System.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
11
actix_rt/system/struct.SystemRunner.html
Normal file
11
actix_rt/system/struct.SystemRunner.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../actix_rt/struct.SystemRunner.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../actix_rt/struct.SystemRunner.html">../../actix_rt/struct.SystemRunner.html</a>...</p>
|
||||
<script>location.replace("../../actix_rt/struct.SystemRunner.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
86
actix_rt/task/fn.spawn_blocking.html
Normal file
86
actix_rt/task/fn.spawn_blocking.html
Normal file
@ -0,0 +1,86 @@
|
||||
<!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="Runs the provided closure on a thread where blocking is acceptable."><title>spawn_blocking in actix_rt::task - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">spawn_<wbr>blocking</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code" title="Related APIs and patterns for bridging asynchronous and blocking code">Related APIs and patterns for bridging asynchronous and blocking code</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>task</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">task</a></span><h1>Function <span class="fn">spawn_blocking</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn spawn_blocking<F, R>(f: F) -> <a class="struct" href="struct.JoinHandle.html" title="struct actix_rt::task::JoinHandle">JoinHandle</a><R> <a href="#" class="tooltip" data-notable-ty="JoinHandle<R>">ⓘ</a><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>() -> R + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,
|
||||
R: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Runs the provided closure on a thread where blocking is acceptable.</p>
|
||||
<p>In general, issuing a blocking call or performing a lot of compute in a
|
||||
future without yielding is problematic, as it may prevent the executor from
|
||||
driving other futures forward. This function runs the provided closure on a
|
||||
thread dedicated to blocking operations. See the <a href="../index.html#cpu-bound-tasks-and-blocking-code">CPU-bound tasks and
|
||||
blocking code</a> section for more information.</p>
|
||||
<p>Tokio will spawn more blocking threads when they are requested through this
|
||||
function until the upper limit configured on the <a href="struct@crate::runtime::Builder"><code>Builder</code></a> is reached.
|
||||
After reaching the upper limit, the tasks are put in a queue.
|
||||
The thread limit is very large by default, because <code>spawn_blocking</code> is often
|
||||
used for various kinds of IO operations that cannot be performed
|
||||
asynchronously. When you run CPU-bound code using <code>spawn_blocking</code>, you
|
||||
should keep this large upper limit in mind. When running many CPU-bound
|
||||
computations, a semaphore or some other synchronization primitive should be
|
||||
used to limit the number of computation executed in parallel. Specialized
|
||||
CPU-bound executors, such as <a href="https://docs.rs/rayon">rayon</a>, may also be a good fit.</p>
|
||||
<p>This function is intended for non-async operations that eventually finish on
|
||||
their own. If you want to spawn an ordinary thread, you should use
|
||||
<a href="https://doc.rust-lang.org/nightly/std/thread/fn.spawn.html" title="fn std::thread::spawn"><code>thread::spawn</code></a> instead.</p>
|
||||
<p>Be aware that tasks spawned using <code>spawn_blocking</code> cannot be aborted
|
||||
because they are not async. If you call <a href="struct.JoinHandle.html#method.abort" title="method actix_rt::task::JoinHandle::abort"><code>abort</code></a> on a <code>spawn_blocking</code>
|
||||
task, then this <em>will not have any effect</em>, and the task will continue
|
||||
running normally. The exception is if the task has not started running
|
||||
yet; in that case, calling <code>abort</code> may prevent the task from starting.</p>
|
||||
<p>When you shut down the executor, it will wait indefinitely for all blocking operations to
|
||||
finish. You can use <a href="fn@crate::runtime::Runtime::shutdown_timeout"><code>shutdown_timeout</code></a> to stop waiting for them after a
|
||||
certain timeout. Be aware that this will still not cancel the tasks — they
|
||||
are simply allowed to keep running after the method returns. It is possible
|
||||
for a blocking task to be cancelled if it has not yet started running, but this
|
||||
is not guaranteed.</p>
|
||||
<p>Note that if you are using the single threaded runtime, this function will
|
||||
still spawn additional threads for blocking operations. The current-thread
|
||||
scheduler’s single thread is only used for asynchronous code.</p>
|
||||
<h2 id="related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code"><a class="doc-anchor" href="#related-apis-and-patterns-for-bridging-asynchronous-and-blocking-code">§</a>Related APIs and patterns for bridging asynchronous and blocking code</h2>
|
||||
<p>In simple cases, it is sufficient to have the closure accept input
|
||||
parameters at creation time and return a single value (or struct/tuple, etc.).</p>
|
||||
<p>For more complex situations in which it is desirable to stream data to or from
|
||||
the synchronous context, the <a href="crate::sync::mpsc"><code>mpsc channel</code></a> has <code>blocking_send</code> and
|
||||
<code>blocking_recv</code> methods for use in non-async code such as the thread created
|
||||
by <code>spawn_blocking</code>.</p>
|
||||
<p>Another option is <a href="https://docs.rs/tokio-util/latest/tokio_util/io/struct.SyncIoBridge.html"><code>SyncIoBridge</code></a> for cases where the synchronous context
|
||||
is operating on byte streams. For example, you might use an asynchronous
|
||||
HTTP client such as <a href="https://docs.rs/hyper">hyper</a> to fetch data, but perform complex parsing
|
||||
of the payload body using a library written for synchronous I/O.</p>
|
||||
<p>Finally, see also <a href="https://tokio.rs/tokio/topics/bridging">Bridging with sync code</a> for discussions
|
||||
around the opposite case of using Tokio as part of a larger synchronous
|
||||
codebase.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Pass an input value and receive result of computation:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
|
||||
<span class="comment">// Initial input
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>v = <span class="string">"Hello, "</span>.to_string();
|
||||
<span class="kw">let </span>res = task::spawn_blocking(<span class="kw">move </span>|| {
|
||||
<span class="comment">// Stand-in for compute-heavy work or using synchronous APIs
|
||||
</span>v.push_str(<span class="string">"world"</span>);
|
||||
<span class="comment">// Pass ownership of the value back to the asynchronous context
|
||||
</span>v
|
||||
}).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// `res` is the value returned from the thread
|
||||
</span><span class="macro">assert_eq!</span>(res.as_str(), <span class="string">"Hello, world"</span>);</code></pre></div>
|
||||
<p>Use a channel:</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::task;
|
||||
<span class="kw">use </span>tokio::sync::mpsc;
|
||||
|
||||
<span class="kw">let </span>(tx, <span class="kw-2">mut </span>rx) = mpsc::channel(<span class="number">2</span>);
|
||||
<span class="kw">let </span>start = <span class="number">5</span>;
|
||||
<span class="kw">let </span>worker = task::spawn_blocking(<span class="kw">move </span>|| {
|
||||
<span class="kw">for </span>x <span class="kw">in </span><span class="number">0</span>..<span class="number">10 </span>{
|
||||
<span class="comment">// Stand in for complex computation
|
||||
</span>tx.blocking_send(start + x).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>acc = <span class="number">0</span>;
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(v) = rx.recv().<span class="kw">await </span>{
|
||||
acc += v;
|
||||
}
|
||||
<span class="macro">assert_eq!</span>(acc, <span class="number">95</span>);
|
||||
worker.<span class="kw">await</span>.unwrap();</code></pre></div>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"JoinHandle<R>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct actix_rt::task::JoinHandle\">JoinHandle</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.JoinHandle.html\" title=\"struct actix_rt::task::JoinHandle\">JoinHandle</a><T></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"enum\" href=\"https://doc.rust-lang.org/nightly/core/result/enum.Result.html\" title=\"enum core::result::Result\">Result</a><T, <a class=\"struct\" href=\"struct.JoinError.html\" title=\"struct actix_rt::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
24
actix_rt/task/fn.yield_now.html
Normal file
24
actix_rt/task/fn.yield_now.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!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="Yields execution back to the Tokio runtime."><title>yield_now in actix_rt::task - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">yield_<wbr>now</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#non-guarantees" title="Non-guarantees">Non-guarantees</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>task</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">task</a></span><h1>Function <span class="fn">yield_now</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub async fn yield_now()</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Yields execution back to the Tokio runtime.</p>
|
||||
<p>A task yields by awaiting on <code>yield_now()</code>, and may resume when that future
|
||||
completes (with no output.) The current task will be re-added as a pending
|
||||
task at the <em>back</em> of the pending queue. Any other pending tasks will be
|
||||
scheduled. No other waking is required for the task to continue.</p>
|
||||
<p>See also the usage example in the <a href="index.html#yield_now">task module</a>.</p>
|
||||
<h3 id="non-guarantees"><a class="doc-anchor" href="#non-guarantees">§</a>Non-guarantees</h3>
|
||||
<p>This function may not yield all the way up to the executor if there are any
|
||||
special combinators above it in the call stack. For example, if a
|
||||
<a href="macro@crate::select"><code>tokio::select!</code></a> has another branch complete during the same poll as the
|
||||
<code>yield_now()</code>, then the yield is not propagated all the way up to the
|
||||
runtime.</p>
|
||||
<p>It is generally not guaranteed that the runtime behaves like you expect it
|
||||
to when deciding which task to schedule next after a call to <code>yield_now()</code>.
|
||||
In particular, the runtime may choose to poll the task that just ran
|
||||
<code>yield_now()</code> again immediately without polling any other tasks first. For
|
||||
example, the runtime will not drive the IO driver between every poll of a
|
||||
task, and this could result in the runtime polling the current task again
|
||||
immediately even if there is another task that could make progress if that
|
||||
other task is waiting for a notification from the IO driver.</p>
|
||||
<p>In general, changes to the order in which the runtime polls tasks is not
|
||||
considered a breaking change, and your program should be correct no matter
|
||||
which order the runtime polls your tasks in.</p>
|
||||
</div></details></section></div></main></body></html>
|
2
actix_rt/task/index.html
Normal file
2
actix_rt/task/index.html
Normal file
@ -0,0 +1,2 @@
|
||||
<!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="Task management (Tokio re-exports)."><title>actix_rt::task - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module task</a></h2><h3><a href="#structs">Module 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"><h2 class="in-crate"><a href="../index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a></span><h1>Module <span>task</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/actix_rt/lib.rs.html#165">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Task management (Tokio re-exports).</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.JoinError.html" title="struct actix_rt::task::JoinError">Join<wbr>Error</a></div><div class="desc docblock-short">Task failed to execute to completion.</div></li><li><div class="item-name"><a class="struct" href="struct.JoinHandle.html" title="struct actix_rt::task::JoinHandle">Join<wbr>Handle</a></div><div class="desc docblock-short">An owned permission to join on a task (await its termination).</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.spawn_blocking.html" title="fn actix_rt::task::spawn_blocking">spawn_<wbr>blocking</a></div><div class="desc docblock-short">Runs the provided closure on a thread where blocking is acceptable.</div></li><li><div class="item-name"><a class="fn" href="fn.yield_now.html" title="fn actix_rt::task::yield_now">yield_<wbr>now</a></div><div class="desc docblock-short">Yields execution back to the Tokio runtime.</div></li></ul></section></div></main></body></html>
|
1
actix_rt/task/sidebar-items.js
Normal file
1
actix_rt/task/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["spawn_blocking","yield_now"],"struct":["JoinError","JoinHandle"]};
|
63
actix_rt/task/struct.JoinError.html
Normal file
63
actix_rt/task/struct.JoinError.html
Normal file
File diff suppressed because one or more lines are too long
291
actix_rt/task/struct.JoinHandle.html
Normal file
291
actix_rt/task/struct.JoinHandle.html
Normal file
File diff suppressed because one or more lines are too long
48
actix_rt/time/fn.interval.html
Normal file
48
actix_rt/time/fn.interval.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!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="Creates new `Interval` that yields with interval of `period`. The first tick completes immediately. The default `MissedTickBehavior` is `Burst`, but this can be configured by calling `set_missed_tick_behavior`."><title>interval in actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">interval</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>time</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">time</a></span><h1>Function <span class="fn">interval</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn interval(period: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="struct" href="struct.Interval.html" title="struct actix_rt::time::Interval">Interval</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates new <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> that yields with interval of <code>period</code>. The first
|
||||
tick completes immediately. The default [<code>MissedTickBehavior</code>] is
|
||||
<a href="MissedTickBehavior::Burst"><code>Burst</code></a>, but this can be configured
|
||||
by calling <a href="struct.Interval.html#method.set_missed_tick_behavior" title="method actix_rt::time::Interval::set_missed_tick_behavior"><code>set_missed_tick_behavior</code></a>.</p>
|
||||
<p>An interval will tick indefinitely. At any time, the <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> value can
|
||||
be dropped. This cancels the interval.</p>
|
||||
<p>This function is equivalent to
|
||||
<a href="fn.interval_at.html" title="fn actix_rt::time::interval_at"><code>interval_at(Instant::now(), period)</code></a>.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if <code>period</code> is zero.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time::{<span class="self">self</span>, Duration};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>interval = time::interval(Duration::from_millis(<span class="number">10</span>));
|
||||
|
||||
interval.tick().<span class="kw">await</span>; <span class="comment">// ticks immediately
|
||||
</span>interval.tick().<span class="kw">await</span>; <span class="comment">// ticks after 10ms
|
||||
</span>interval.tick().<span class="kw">await</span>; <span class="comment">// ticks after 10ms
|
||||
|
||||
// approximately 20ms have elapsed.
|
||||
</span>}</code></pre></div>
|
||||
<p>A simple example using <code>interval</code> to execute a task every two seconds.</p>
|
||||
<p>The difference between <code>interval</code> and <a href="fn.sleep.html" title="fn actix_rt::time::sleep"><code>sleep</code></a> is that an <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a>
|
||||
measures the time since the last tick, which means that <a href="struct.Interval.html#method.tick" title="method actix_rt::time::Interval::tick"><code>.tick().await</code></a>
|
||||
may wait for a shorter time than the duration specified for the interval
|
||||
if some time has passed between calls to <a href="struct.Interval.html#method.tick" title="method actix_rt::time::Interval::tick"><code>.tick().await</code></a>.</p>
|
||||
<p>If the tick in the example below was replaced with <a href="fn.sleep.html" title="fn actix_rt::time::sleep"><code>sleep</code></a>, the task
|
||||
would only be executed once every three seconds, and not every two
|
||||
seconds.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time;
|
||||
|
||||
<span class="kw">async fn </span>task_that_takes_a_second() {
|
||||
<span class="macro">println!</span>(<span class="string">"hello"</span>);
|
||||
time::sleep(time::Duration::from_secs(<span class="number">1</span>)).<span class="kw">await
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>interval = time::interval(time::Duration::from_secs(<span class="number">2</span>));
|
||||
<span class="kw">for </span>_i <span class="kw">in </span><span class="number">0</span>..<span class="number">5 </span>{
|
||||
interval.tick().<span class="kw">await</span>;
|
||||
task_that_takes_a_second().<span class="kw">await</span>;
|
||||
}
|
||||
}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
23
actix_rt/time/fn.interval_at.html
Normal file
23
actix_rt/time/fn.interval_at.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!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="Creates new `Interval` that yields with interval of `period` with the first tick completing at `start`. The default `MissedTickBehavior` is `Burst`, but this can be configured by calling `set_missed_tick_behavior`."><title>interval_at in actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">interval_<wbr>at</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#panics" title="Panics">Panics</a></li><li><a href="#examples" title="Examples">Examples</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>time</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">time</a></span><h1>Function <span class="fn">interval_at</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn interval_at(start: <a class="struct" href="struct.Instant.html" title="struct actix_rt::time::Instant">Instant</a>, period: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="struct" href="struct.Interval.html" title="struct actix_rt::time::Interval">Interval</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates new <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> that yields with interval of <code>period</code> with the
|
||||
first tick completing at <code>start</code>. The default [<code>MissedTickBehavior</code>] is
|
||||
<a href="MissedTickBehavior::Burst"><code>Burst</code></a>, but this can be configured
|
||||
by calling <a href="struct.Interval.html#method.set_missed_tick_behavior" title="method actix_rt::time::Interval::set_missed_tick_behavior"><code>set_missed_tick_behavior</code></a>.</p>
|
||||
<p>An interval will tick indefinitely. At any time, the <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> value can
|
||||
be dropped. This cancels the interval.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if <code>period</code> is zero.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time::{interval_at, Duration, Instant};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
<span class="kw">let </span>start = Instant::now() + Duration::from_millis(<span class="number">50</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>interval = interval_at(start, Duration::from_millis(<span class="number">10</span>));
|
||||
|
||||
interval.tick().<span class="kw">await</span>; <span class="comment">// ticks after 50ms
|
||||
</span>interval.tick().<span class="kw">await</span>; <span class="comment">// ticks after 10ms
|
||||
</span>interval.tick().<span class="kw">await</span>; <span class="comment">// ticks after 10ms
|
||||
|
||||
// approximately 70ms have elapsed.
|
||||
</span>}</code></pre></div>
|
||||
</div></details></section></div></main></body></html>
|
36
actix_rt/time/fn.sleep.html
Normal file
36
actix_rt/time/fn.sleep.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!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="Waits until `duration` has elapsed."><title>sleep in actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">sleep</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#cancellation" title="Cancellation">Cancellation</a></li><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>time</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">time</a></span><h1>Function <span class="fn">sleep</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn sleep(duration: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="struct" href="struct.Sleep.html" title="struct actix_rt::time::Sleep">Sleep</a> <a href="#" class="tooltip" data-notable-ty="Sleep">ⓘ</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Waits until <code>duration</code> has elapsed.</p>
|
||||
<p>Equivalent to <code>sleep_until(Instant::now() + duration)</code>. An asynchronous
|
||||
analog to <code>std::thread::sleep</code>.</p>
|
||||
<p>No work is performed while awaiting on the sleep future to complete. <code>Sleep</code>
|
||||
operates at millisecond granularity and should not be used for tasks that
|
||||
require high-resolution timers. The implementation is platform specific,
|
||||
and some platforms (specifically Windows) will provide timers with a
|
||||
larger resolution than 1 ms.</p>
|
||||
<p>To run something regularly on a schedule, see <a href="fn.interval.html" title="fn actix_rt::time::interval"><code>interval</code></a>.</p>
|
||||
<p>The maximum duration for a sleep is 68719476734 milliseconds (approximately 2.2 years).</p>
|
||||
<h2 id="cancellation"><a class="doc-anchor" href="#cancellation">§</a>Cancellation</h2>
|
||||
<p>Canceling a sleep instance is done by dropping the returned future. No additional
|
||||
cleanup work is required.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Wait 100ms and print “100 ms have elapsed”.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time::{sleep, Duration};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
sleep(Duration::from_millis(<span class="number">100</span>)).<span class="kw">await</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"100 ms have elapsed"</span>);
|
||||
}</code></pre></div>
|
||||
<p>See the documentation for the <a href="struct.Sleep.html" title="struct actix_rt::time::Sleep"><code>Sleep</code></a> type for more examples.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if there is no current timer set.</p>
|
||||
<p>It can be triggered when <a href="crate::runtime::Builder::enable_time"><code>Builder::enable_time</code></a> or
|
||||
<a href="crate::runtime::Builder::enable_all"><code>Builder::enable_all</code></a> are not included in the builder.</p>
|
||||
<p>It can also panic whenever a timer is created outside of a
|
||||
Tokio runtime. That is why <code>rt.block_on(sleep(...))</code> will panic,
|
||||
since the function is executed outside of the runtime.
|
||||
Whereas <code>rt.block_on(async {sleep(...).await})</code> doesn’t panic.
|
||||
And this is because wrapping the function on an async makes it lazy,
|
||||
and so gets executed inside the runtime successfully without
|
||||
panicking.</p>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"Sleep":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Sleep.html\" title=\"struct actix_rt::time::Sleep\">Sleep</a></code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.Sleep.html\" title=\"struct actix_rt::time::Sleep\">Sleep</a></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.unit.html\">()</a>;</div>"}</script></section></div></main></body></html>
|
31
actix_rt/time/fn.sleep_until.html
Normal file
31
actix_rt/time/fn.sleep_until.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!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="Waits until `deadline` is reached."><title>sleep_until in actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">sleep_<wbr>until</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#cancellation" title="Cancellation">Cancellation</a></li><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>time</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">time</a></span><h1>Function <span class="fn">sleep_until</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn sleep_until(deadline: <a class="struct" href="struct.Instant.html" title="struct actix_rt::time::Instant">Instant</a>) -> <a class="struct" href="struct.Sleep.html" title="struct actix_rt::time::Sleep">Sleep</a> <a href="#" class="tooltip" data-notable-ty="Sleep">ⓘ</a></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Waits until <code>deadline</code> is reached.</p>
|
||||
<p>No work is performed while awaiting on the sleep future to complete. <code>Sleep</code>
|
||||
operates at millisecond granularity and should not be used for tasks that
|
||||
require high-resolution timers.</p>
|
||||
<p>To run something regularly on a schedule, see <a href="fn.interval.html" title="fn actix_rt::time::interval"><code>interval</code></a>.</p>
|
||||
<h2 id="cancellation"><a class="doc-anchor" href="#cancellation">§</a>Cancellation</h2>
|
||||
<p>Canceling a sleep instance is done by dropping the returned future. No additional
|
||||
cleanup work is required.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Wait 100ms and print “100 ms have elapsed”.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time::{sleep_until, Instant, Duration};
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() {
|
||||
sleep_until(Instant::now() + Duration::from_millis(<span class="number">100</span>)).<span class="kw">await</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"100 ms have elapsed"</span>);
|
||||
}</code></pre></div>
|
||||
<p>See the documentation for the <a href="struct.Sleep.html" title="struct actix_rt::time::Sleep"><code>Sleep</code></a> type for more examples.</p>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if there is no current timer set.</p>
|
||||
<p>It can be triggered when <a href="crate::runtime::Builder::enable_time"><code>Builder::enable_time</code></a> or
|
||||
<a href="crate::runtime::Builder::enable_all"><code>Builder::enable_all</code></a> are not included in the builder.</p>
|
||||
<p>It can also panic whenever a timer is created outside of a
|
||||
Tokio runtime. That is why <code>rt.block_on(sleep(...))</code> will panic,
|
||||
since the function is executed outside of the runtime.
|
||||
Whereas <code>rt.block_on(async {sleep(...).await})</code> doesn’t panic.
|
||||
And this is because wrapping the function on an async makes it lazy,
|
||||
and so gets executed inside the runtime successfully without
|
||||
panicking.</p>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"Sleep":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Sleep.html\" title=\"struct actix_rt::time::Sleep\">Sleep</a></code></h3><pre><code><div class=\"where\">impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.Sleep.html\" title=\"struct actix_rt::time::Sleep\">Sleep</a></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"primitive\" href=\"https://doc.rust-lang.org/nightly/std/primitive.unit.html\">()</a>;</div>"}</script></section></div></main></body></html>
|
47
actix_rt/time/fn.timeout.html
Normal file
47
actix_rt/time/fn.timeout.html
Normal file
@ -0,0 +1,47 @@
|
||||
<!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="Requires a `Future` to complete before the specified duration has elapsed."><title>timeout in actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">timeout</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#cancellation" title="Cancellation">Cancellation</a></li><li><a href="#examples" title="Examples">Examples</a></li><li><a href="#panics" title="Panics">Panics</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In actix_<wbr>rt::<wbr>time</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a>::<wbr><a href="index.html">time</a></span><h1>Function <span class="fn">timeout</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>pub fn timeout<F>(
|
||||
duration: <a class="struct" href="https://doc.rust-lang.org/nightly/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>,
|
||||
future: F,
|
||||
) -> <a class="struct" href="struct.Timeout.html" title="struct actix_rt::time::Timeout">Timeout</a><<F as <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/into_future/trait.IntoFuture.html" title="trait core::future::into_future::IntoFuture">IntoFuture</a>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/future/into_future/trait.IntoFuture.html#associatedtype.IntoFuture" title="type core::future::into_future::IntoFuture::IntoFuture">IntoFuture</a>> <a href="#" class="tooltip" data-notable-ty="Timeout<<F as IntoFuture>::IntoFuture>">ⓘ</a><div class="where">where
|
||||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/future/into_future/trait.IntoFuture.html" title="trait core::future::into_future::IntoFuture">IntoFuture</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Requires a <code>Future</code> to complete before the specified duration has elapsed.</p>
|
||||
<p>If the future completes before the duration has elapsed, then the completed
|
||||
value is returned. Otherwise, an error is returned and the future is
|
||||
canceled.</p>
|
||||
<p>Note that the timeout is checked before polling the future, so if the future
|
||||
does not yield during execution then it is possible for the future to complete
|
||||
and exceed the timeout <em>without</em> returning an error.</p>
|
||||
<p>This function returns a future whose return type is <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result"><code>Result</code></a><code><T,</code><a href="crate::time::error::Elapsed"><code>Elapsed</code></a><code>></code>, where <code>T</code> is the
|
||||
return type of the provided future.</p>
|
||||
<p>If the provided future completes immediately, then the future returned from
|
||||
this function is guaranteed to complete immediately with an <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="variant core::result::Result::Ok"><code>Ok</code></a> variant
|
||||
no matter the provided duration.</p>
|
||||
<h2 id="cancellation"><a class="doc-anchor" href="#cancellation">§</a>Cancellation</h2>
|
||||
<p>Cancelling a timeout is done by dropping the future. No additional cleanup
|
||||
or other work is required.</p>
|
||||
<p>The original future may be obtained by calling <a href="struct.Timeout.html#method.into_inner" title="method actix_rt::time::Timeout::into_inner"><code>Timeout::into_inner</code></a>. This
|
||||
consumes the <code>Timeout</code>.</p>
|
||||
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
|
||||
<p>Create a new <code>Timeout</code> set to expire in 10 milliseconds.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::time::timeout;
|
||||
<span class="kw">use </span>tokio::sync::oneshot;
|
||||
|
||||
<span class="kw">use </span>std::time::Duration;
|
||||
|
||||
<span class="kw">let </span>(tx, rx) = oneshot::channel();
|
||||
|
||||
<span class="comment">// Wrap the future with a `Timeout` set to expire in 10 milliseconds.
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(<span class="kw">_</span>) = timeout(Duration::from_millis(<span class="number">10</span>), rx).<span class="kw">await </span>{
|
||||
<span class="macro">println!</span>(<span class="string">"did not receive value within 10 ms"</span>);
|
||||
}</code></pre></div>
|
||||
<h2 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h2>
|
||||
<p>This function panics if there is no current timer set.</p>
|
||||
<p>It can be triggered when <a href="crate::runtime::Builder::enable_time"><code>Builder::enable_time</code></a> or
|
||||
<a href="crate::runtime::Builder::enable_all"><code>Builder::enable_all</code></a> are not included in the builder.</p>
|
||||
<p>It can also panic whenever a timer is created outside of a
|
||||
Tokio runtime. That is why <code>rt.block_on(sleep(...))</code> will panic,
|
||||
since the function is executed outside of the runtime.
|
||||
Whereas <code>rt.block_on(async {sleep(...).await})</code> doesn’t panic.
|
||||
And this is because wrapping the function on an async makes it lazy,
|
||||
and so gets executed inside the runtime successfully without
|
||||
panicking.</p>
|
||||
</div></details><script type="text/json" id="notable-traits-data">{"Timeout<<F as IntoFuture>::IntoFuture>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Timeout.html\" title=\"struct actix_rt::time::Timeout\">Timeout</a><T></code></h3><pre><code><div class=\"where\">impl<T> <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a> for <a class=\"struct\" href=\"struct.Timeout.html\" title=\"struct actix_rt::time::Timeout\">Timeout</a><T><div class=\"where\">where\n T: <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a>,</div></div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" class=\"associatedtype\">Output</a> = <a class=\"enum\" href=\"https://doc.rust-lang.org/nightly/core/result/enum.Result.html\" title=\"enum core::result::Result\">Result</a><<T as <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html\" title=\"trait core::future::future::Future\">Future</a>>::<a class=\"associatedtype\" href=\"https://doc.rust-lang.org/nightly/core/future/future/trait.Future.html#associatedtype.Output\" title=\"type core::future::future::Future::Output\">Output</a>, Elapsed>;</div>"}</script></section></div></main></body></html>
|
9
actix_rt/time/index.html
Normal file
9
actix_rt/time/index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!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="Utilities for tracking time (Tokio re-exports)."><title>actix_rt::time - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../../static.files/rustdoc-b778ab399e080a4b.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_rt" data-themes="" data-resource-suffix="" data-rustdoc-version="1.83.0-nightly (7608018cb 2024-09-29)" data-channel="nightly" data-search-js="search-e056c65ede92db13.js" data-settings-js="settings-805db61a62df4bd2.js" ><script src="../../static.files/storage-1d39b6787ed640ff.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-54bc299d2a5e4e43.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-0111fcff984fae8f.css"></noscript><link rel="icon" href="https://actix.rs/favicon.ico"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../../actix_rt/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_rt/index.html">actix_<wbr>rt</a><span class="version">2.10.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module time</a></h2><h3><a href="#structs">Module 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"><h2 class="in-crate"><a href="../index.html">In crate actix_<wbr>rt</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">actix_rt</a></span><h1>Module <span>time</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/actix_rt/lib.rs.html#157">source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Utilities for tracking time (Tokio re-exports).</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Instant.html" title="struct actix_rt::time::Instant">Instant</a></div><div class="desc docblock-short">A measurement of a monotonically nondecreasing clock.
|
||||
Opaque and useful only with <code>Duration</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.Interval.html" title="struct actix_rt::time::Interval">Interval</a></div><div class="desc docblock-short">Interval returned by <a href="fn.interval.html" title="fn actix_rt::time::interval"><code>interval</code></a> and <a href="fn.interval_at.html" title="fn actix_rt::time::interval_at"><code>interval_at</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.Sleep.html" title="struct actix_rt::time::Sleep">Sleep</a></div><div class="desc docblock-short">Future returned by <a href="fn.sleep.html" title="fn actix_rt::time::sleep"><code>sleep</code></a> and <a href="fn.sleep_until.html" title="fn actix_rt::time::sleep_until"><code>sleep_until</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.Timeout.html" title="struct actix_rt::time::Timeout">Timeout</a></div><div class="desc docblock-short">Future returned by <a href="fn.timeout.html" title="fn actix_rt::time::timeout"><code>timeout</code></a> and <a href="timeout_at"><code>timeout_at</code></a>.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.interval.html" title="fn actix_rt::time::interval">interval</a></div><div class="desc docblock-short">Creates new <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> that yields with interval of <code>period</code>. The first
|
||||
tick completes immediately. The default [<code>MissedTickBehavior</code>] is
|
||||
<a href="MissedTickBehavior::Burst"><code>Burst</code></a>, but this can be configured
|
||||
by calling <a href="struct.Interval.html#method.set_missed_tick_behavior" title="method actix_rt::time::Interval::set_missed_tick_behavior"><code>set_missed_tick_behavior</code></a>.</div></li><li><div class="item-name"><a class="fn" href="fn.interval_at.html" title="fn actix_rt::time::interval_at">interval_<wbr>at</a></div><div class="desc docblock-short">Creates new <a href="struct.Interval.html" title="struct actix_rt::time::Interval"><code>Interval</code></a> that yields with interval of <code>period</code> with the
|
||||
first tick completing at <code>start</code>. The default [<code>MissedTickBehavior</code>] is
|
||||
<a href="MissedTickBehavior::Burst"><code>Burst</code></a>, but this can be configured
|
||||
by calling <a href="struct.Interval.html#method.set_missed_tick_behavior" title="method actix_rt::time::Interval::set_missed_tick_behavior"><code>set_missed_tick_behavior</code></a>.</div></li><li><div class="item-name"><a class="fn" href="fn.sleep.html" title="fn actix_rt::time::sleep">sleep</a></div><div class="desc docblock-short">Waits until <code>duration</code> has elapsed.</div></li><li><div class="item-name"><a class="fn" href="fn.sleep_until.html" title="fn actix_rt::time::sleep_until">sleep_<wbr>until</a></div><div class="desc docblock-short">Waits until <code>deadline</code> is reached.</div></li><li><div class="item-name"><a class="fn" href="fn.timeout.html" title="fn actix_rt::time::timeout">timeout</a></div><div class="desc docblock-short">Requires a <code>Future</code> to complete before the specified duration has elapsed.</div></li></ul></section></div></main></body></html>
|
1
actix_rt/time/sidebar-items.js
Normal file
1
actix_rt/time/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["interval","interval_at","sleep","sleep_until","timeout"],"struct":["Instant","Interval","Sleep","Timeout"]};
|
96
actix_rt/time/struct.Instant.html
Normal file
96
actix_rt/time/struct.Instant.html
Normal file
File diff suppressed because one or more lines are too long
144
actix_rt/time/struct.Interval.html
Normal file
144
actix_rt/time/struct.Interval.html
Normal file
File diff suppressed because one or more lines are too long
152
actix_rt/time/struct.Sleep.html
Normal file
152
actix_rt/time/struct.Sleep.html
Normal file
File diff suppressed because one or more lines are too long
114
actix_rt/time/struct.Timeout.html
Normal file
114
actix_rt/time/struct.Timeout.html
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user