mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-30 16:34:26 +02:00
Deploying to gh-pages from @ actix/actix-web@26efa64278 🚀
This commit is contained in:
24
actix_web/rt/fn.spawn.html
Normal file
24
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt</a></h2></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>Function <a href="../index.html">actix_web</a>::<wbr><a href="index.html">rt</a>::<wbr><a class="fn" href="#">spawn</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::rt::task::JoinHandle">JoinHandle</a><<Fut 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>> <a href="#" class="tooltip" data-notable-ty="JoinHandle<<Fut as Future>::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 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>: '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_web::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 as Future>::Output>":"<h3>Notable traits for <code><a class=\"struct\" href=\"task/struct.JoinHandle.html\" title=\"struct actix_web::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_web::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_web::rt::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
50
actix_web/rt/index.html
Normal file
50
actix_web/rt/index.html
Normal file
@ -0,0 +1,50 @@
|
||||
<!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="A selection of re-exports from `tokio` and `actix-rt`."><title>actix_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module rt</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#macros">Macros</a></li><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section><h2><a href="../index.html">In crate actix_web</a></h2></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>Module <a href="../index.html">actix_web</a>::<wbr><a class="mod" href="#">rt</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><a class="src" href="../../src/actix_web/rt.rs.html#1-78">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A selection of re-exports from <a href="https://docs.rs/tokio"><code>tokio</code></a> and <a href="https://docs.rs/actix-rt"><code>actix-rt</code></a>.</p>
|
||||
<p>Actix Web runs on <a href="https://docs.rs/tokio">Tokio</a>, providing full<sup id="fnref1"><a href="#fn1">1</a></sup> compatibility with its huge ecosystem of
|
||||
crates. Each of the server’s workers uses a single-threaded runtime. Read more about the
|
||||
architecture in <a href="https://docs.rs/actix-rt"><code>actix-rt</code></a>’s docs.</p>
|
||||
<h2 id="running-actix-web-without-macros"><a class="doc-anchor" href="#running-actix-web-without-macros">§</a>Running Actix Web Without Macros</h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{middleware, rt, web, App, HttpRequest, HttpServer};
|
||||
|
||||
<span class="kw">async fn </span>index(req: HttpRequest) -> <span class="kw-2">&</span><span class="lifetime">'static </span>str {
|
||||
<span class="macro">println!</span>(<span class="string">"REQ: {:?}"</span>, req);
|
||||
<span class="string">"Hello world!\r\n"
|
||||
</span>}
|
||||
|
||||
<span class="kw">fn </span>main() -> std::io::Result<()> {
|
||||
rt::System::new().block_on(
|
||||
HttpServer::new(|| {
|
||||
App::new().service(web::resource(<span class="string">"/"</span>).route(web::get().to(index)))
|
||||
})
|
||||
.bind((<span class="string">"127.0.0.1"</span>, <span class="number">8080</span>))<span class="question-mark">?
|
||||
</span>.run()
|
||||
)
|
||||
}</code></pre></div>
|
||||
<h2 id="running-actix-web-using-tokiomain"><a class="doc-anchor" href="#running-actix-web-using-tokiomain">§</a>Running Actix Web Using <code>#[tokio::main]</code></h2>
|
||||
<p>If you need to run something that uses Tokio’s work stealing functionality alongside Actix Web,
|
||||
you can run Actix Web under <code>#[tokio::main]</code>. The <a href="../dev/struct.Server.html" title="struct actix_web::dev::Server"><code>Server</code></a> object returned
|
||||
from <a href="../struct.HttpServer.html#method.run" title="method actix_web::HttpServer::run"><code>HttpServer::run</code></a> can also be <a href="https://docs.rs/tokio/1/tokio/fn.spawn.html"><code>spawn</code></a>ed, if preferred.</p>
|
||||
<p>Note that <code>actix</code> actor support (and therefore WebSocket support through <code>actix-web-actors</code>)
|
||||
still require <code>#[actix_web::main]</code> since they require a <a href="struct.System.html" title="struct actix_web::rt::System"><code>System</code></a> to be set up.</p>
|
||||
<p>Also note that calls to this module’s <a href="fn.spawn.html" title="fn actix_web::rt::spawn"><code>spawn()</code></a> re-export require an <code>#[actix_web::main]</code>
|
||||
runtime (or a manually configured <code>LocalSet</code>) since it makes calls into to the current thread’s
|
||||
<code>LocalSet</code>, which <code>#[tokio::main]</code> does not set up.</p>
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>actix_web::{get, middleware, rt, web, App, HttpRequest, HttpServer};
|
||||
|
||||
<span class="attr">#[get(<span class="string">"/"</span>)]
|
||||
</span><span class="kw">async fn </span>index(req: HttpRequest) -> <span class="kw-2">&</span><span class="lifetime">'static </span>str {
|
||||
<span class="macro">println!</span>(<span class="string">"REQ: {:?}"</span>, req);
|
||||
<span class="string">"Hello world!\r\n"
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[tokio::main]
|
||||
</span><span class="kw">async fn </span>main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().service(index)
|
||||
})
|
||||
.bind((<span class="string">"127.0.0.1"</span>, <span class="number">8080</span>))<span class="question-mark">?
|
||||
</span>.run()
|
||||
.<span class="kw">await
|
||||
</span>}</code></pre></div>
|
||||
<div class="footnotes"><hr><ol><li id="fn1"><p>Crates that use Tokio’s <a href="https://docs.rs/tokio/1/tokio/task/fn.block_in_place.html"><code>block_in_place</code></a> will not work with Actix Web. Fortunately,
|
||||
the vast majority of Tokio-based crates do not use it. <a href="#fnref1">↩</a></p></li></ol></div></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_web::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_web::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_web::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_web::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_web::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.Runtime.html" title="struct actix_web::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_web::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_web::rt::SystemRunner">SystemRunner</a></div><div class="desc docblock-short">Runner that keeps a <a href="struct.System.html" title="struct actix_web::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_web::rt::spawn">spawn</a></div><div class="desc docblock-short">Spawns a future on the current thread as a new task.</div></li></ul></section></div></main></body></html>
|
11
actix_web/rt/macro.pin!.html
Normal file
11
actix_web/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_web/rt/macro.pin.html
Normal file
104
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt</a></h2></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>Macro <a href="../index.html">actix_web</a>::<wbr><a href="index.html">rt</a>::<wbr><a class="macro" href="#">pin</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web/rt/net/index.html
Normal file
3
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module net</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li></ul></section><h2><a href="../index.html">In actix_web::rt</a></h2></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>Module <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a class="mod" href="#">net</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::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_web::rt::net::TcpListener">TcpListener</a><span class="stab portability" title="Available on crate feature `net` only"><code>net</code></span></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_web::rt::net::TcpSocket">TcpSocket</a><span class="stab portability" title="Available on crate feature `net` only"><code>net</code></span></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_web::rt::net::TcpStream">TcpStream</a><span class="stab portability" title="Available on crate feature `net` only"><code>net</code></span></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_web::rt::net::UdpSocket">UdpSocket</a><span class="stab portability" title="Available on crate feature `net` only"><code>net</code></span></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_web::rt::net::UnixDatagram">UnixDatagram</a><span class="stab portability" title="Available on Unix and crate feature `net` only">Unix and <code>net</code></span></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_web::rt::net::UnixListener">UnixListener</a><span class="stab portability" title="Available on Unix and crate feature `net` only">Unix and <code>net</code></span></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_web::rt::net::UnixStream">UnixStream</a><span class="stab portability" title="Available on Unix and crate feature `net` only">Unix and <code>net</code></span></div><div class="desc docblock-short">A structure representing a connected Unix socket.</div></li></ul></section></div></main></body></html>
|
1
actix_web/rt/net/sidebar-items.js
Normal file
1
actix_web/rt/net/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"struct":["Ready","TcpListener","TcpSocket","TcpStream","UdpSocket","UnixDatagram","UnixListener","UnixStream"]};
|
91
actix_web/rt/net/struct.Ready.html
Normal file
91
actix_web/rt/net/struct.Ready.html
Normal file
File diff suppressed because one or more lines are too long
204
actix_web/rt/net/struct.TcpListener.html
Normal file
204
actix_web/rt/net/struct.TcpListener.html
Normal file
File diff suppressed because one or more lines are too long
400
actix_web/rt/net/struct.TcpSocket.html
Normal file
400
actix_web/rt/net/struct.TcpSocket.html
Normal file
File diff suppressed because one or more lines are too long
891
actix_web/rt/net/struct.TcpStream.html
Normal file
891
actix_web/rt/net/struct.TcpStream.html
Normal file
File diff suppressed because one or more lines are too long
1188
actix_web/rt/net/struct.UdpSocket.html
Normal file
1188
actix_web/rt/net/struct.UdpSocket.html
Normal file
File diff suppressed because one or more lines are too long
1009
actix_web/rt/net/struct.UnixDatagram.html
Normal file
1009
actix_web/rt/net/struct.UnixDatagram.html
Normal file
File diff suppressed because one or more lines are too long
96
actix_web/rt/net/struct.UnixListener.html
Normal file
96
actix_web/rt/net/struct.UnixListener.html
Normal file
File diff suppressed because one or more lines are too long
750
actix_web/rt/net/struct.UnixStream.html
Normal file
750
actix_web/rt/net/struct.UnixStream.html
Normal file
File diff suppressed because one or more lines are too long
1
actix_web/rt/sidebar-items.js
Normal file
1
actix_web/rt/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["spawn"],"macro":["pin"],"mod":["net","signal","task","time"],"struct":["Runtime","System","SystemRunner"]};
|
39
actix_web/rt/signal/fn.ctrl_c.html
Normal file
39
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::signal</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">signal</a>::<wbr><a class="fn" href="#">ctrl_c</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web/rt/signal/index.html
Normal file
2
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module signal</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#functions">Functions</a></li></ul></section><h2><a href="../index.html">In actix_web::rt</a></h2></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>Module <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a class="mod" href="#">signal</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::rt::signal::unix">unix</a><span class="stab portability" title="Available on Unix only">Unix</span></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_web::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_web/rt/signal/sidebar-items.js
Normal file
1
actix_web/rt/signal/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["ctrl_c"],"mod":["unix"]};
|
25
actix_web/rt/signal/unix/fn.signal.html
Normal file
25
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::signal::unix</a></h2></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>Function <a href="../../../index.html">actix_web</a>::<wbr><a href="../../index.html">rt</a>::<wbr><a href="../index.html">signal</a>::<wbr><a href="index.html">unix</a>::<wbr><a class="fn" href="#">signal</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn signal(kind: <a class="struct" href="struct.SignalKind.html" title="struct actix_web::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_web::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><span class="item-info"><div class="stab portability">Available on <strong>Unix</strong> only.</div></span><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_web/rt/signal/unix/index.html
Normal file
3
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module unix</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section><h2><a href="../index.html">In actix_web::rt::signal</a></h2></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>Module <a href="../../../index.html">actix_web</a>::<wbr><a href="../../index.html">rt</a>::<wbr><a href="../index.html">signal</a>::<wbr><a class="mod" href="#">unix</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><span class="item-info"><div class="stab portability">Available on <strong>Unix</strong> only.</div></span><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_web::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_web::rt::signal::unix::SignalKind">SignalKind</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_web::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_web/rt/signal/unix/sidebar-items.js
Normal file
1
actix_web/rt/signal/unix/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["signal"],"struct":["Signal","SignalKind"]};
|
125
actix_web/rt/signal/unix/struct.Signal.html
Normal file
125
actix_web/rt/signal/unix/struct.Signal.html
Normal file
File diff suppressed because one or more lines are too long
73
actix_web/rt/signal/unix/struct.SignalKind.html
Normal file
73
actix_web/rt/signal/unix/struct.SignalKind.html
Normal file
File diff suppressed because one or more lines are too long
91
actix_web/rt/struct.Runtime.html
Normal file
91
actix_web/rt/struct.Runtime.html
Normal file
File diff suppressed because one or more lines are too long
34
actix_web/rt/struct.System.html
Normal file
34
actix_web/rt/struct.System.html
Normal file
File diff suppressed because one or more lines are too long
22
actix_web/rt/struct.SystemRunner.html
Normal file
22
actix_web/rt/struct.SystemRunner.html
Normal file
File diff suppressed because one or more lines are too long
89
actix_web/rt/task/fn.spawn_blocking.html
Normal file
89
actix_web/rt/task/fn.spawn_blocking.html
Normal file
@ -0,0 +1,89 @@
|
||||
<!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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::task</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">task</a>::<wbr><a class="fn" href="#">spawn_blocking</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::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><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>rt</code></strong> only.</div></span><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>Closures spawned using <code>spawn_blocking</code> cannot be cancelled abruptly; there
|
||||
is no standard low level API to cause a thread to stop running. However,
|
||||
a useful pattern is to pass some form of “cancellation token” into
|
||||
the thread. This could be an <a href="https://doc.rust-lang.org/nightly/core/sync/atomic/struct.AtomicBool.html" title="struct core::sync::atomic::AtomicBool"><code>AtomicBool</code></a> that the task checks periodically.
|
||||
Another approach is to have the thread primarily read or write from a channel,
|
||||
and to exit when the channel closes; assuming the other side of the channel is dropped
|
||||
when cancellation occurs, this will cause the blocking task thread to exit
|
||||
soon after as well.</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_web::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_web::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_web::rt::task::JoinError\">JoinError</a>>;</div>"}</script></section></div></main></body></html>
|
24
actix_web/rt/task/fn.yield_now.html
Normal file
24
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::task</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">task</a>::<wbr><a class="fn" href="#">yield_now</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web/rt/task/index.html
Normal file
2
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module task</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section><h2><a href="../index.html">In actix_web::rt</a></h2></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>Module <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a class="mod" href="#">task</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::rt::task::JoinError">JoinError</a><span class="stab portability" title="Available on crate feature `rt` only"><code>rt</code></span></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_web::rt::task::JoinHandle">JoinHandle</a><span class="stab portability" title="Available on crate feature `rt` only"><code>rt</code></span></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_web::rt::task::spawn_blocking">spawn_blocking</a><span class="stab portability" title="Available on crate feature `rt` only"><code>rt</code></span></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_web::rt::task::yield_now">yield_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_web/rt/task/sidebar-items.js
Normal file
1
actix_web/rt/task/sidebar-items.js
Normal file
@ -0,0 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"fn":["spawn_blocking","yield_now"],"struct":["JoinError","JoinHandle"]};
|
69
actix_web/rt/task/struct.JoinError.html
Normal file
69
actix_web/rt/task/struct.JoinError.html
Normal file
File diff suppressed because one or more lines are too long
295
actix_web/rt/task/struct.JoinHandle.html
Normal file
295
actix_web/rt/task/struct.JoinHandle.html
Normal file
File diff suppressed because one or more lines are too long
48
actix_web/rt/time/fn.interval.html
Normal file
48
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::time</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">time</a>::<wbr><a class="fn" href="#">interval</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::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_web::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_web::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_web::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_web::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_web::rt::time::sleep"><code>sleep</code></a> is that an <a href="struct.Interval.html" title="struct actix_web::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_web::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_web::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_web::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_web/rt/time/fn.interval_at.html
Normal file
23
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::time</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">time</a>::<wbr><a class="fn" href="#">interval_at</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn interval_at(start: <a class="struct" href="struct.Instant.html" title="struct actix_web::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_web::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_web::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_web::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_web::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_web/rt/time/fn.sleep.html
Normal file
36
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::time</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">time</a>::<wbr><a class="fn" href="#">sleep</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::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_web::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_web::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_web::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_web::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_web/rt/time/fn.sleep_until.html
Normal file
31
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::time</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">time</a>::<wbr><a class="fn" href="#">sleep_until</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><pre class="rust item-decl"><code>pub fn sleep_until(deadline: <a class="struct" href="struct.Instant.html" title="struct actix_web::rt::time::Instant">Instant</a>) -> <a class="struct" href="struct.Sleep.html" title="struct actix_web::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_web::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_web::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_web::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_web::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>
|
44
actix_web/rt/time/fn.timeout.html
Normal file
44
actix_web/rt/time/fn.timeout.html
Normal file
@ -0,0 +1,44 @@
|
||||
<!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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><div class="sidebar-elems"><h2><a href="index.html">In actix_web::rt::time</a></h2></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>Function <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a href="index.html">time</a>::<wbr><a class="fn" href="#">timeout</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::rt::time::Timeout">Timeout</a><F> <a href="#" class="tooltip" data-notable-ty="Timeout<F>">ⓘ</a><div class="where">where
|
||||
F: <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></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_web::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>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Timeout.html\" title=\"struct actix_web::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_web::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_web/rt/time/index.html
Normal file
9
actix_web/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_web::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-dd39b87e5fcfba68.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="actix_web" data-themes="" data-resource-suffix="" data-rustdoc-version="1.80.0-nightly (bdbbb6c6a 2024-05-26)" data-channel="nightly" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../../../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-df360f571f6edeae.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_web/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_web/index.html"><img src="https://actix.rs/img/logo.png" alt="logo"></a><h2><a href="../../../actix_web/index.html">actix_web</a><span class="version">4.6.0</span></h2></div><h2 class="location"><a href="#">Module time</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#functions">Functions</a></li></ul></section><h2><a href="../index.html">In actix_web::rt</a></h2></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>Module <a href="../../index.html">actix_web</a>::<wbr><a href="../index.html">rt</a>::<wbr><a class="mod" href="#">time</a><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><span class="out-of-band"><button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></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_web::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_web::rt::time::Interval">Interval</a></div><div class="desc docblock-short">Interval returned by <a href="fn.interval.html" title="fn actix_web::rt::time::interval"><code>interval</code></a> and <a href="fn.interval_at.html" title="fn actix_web::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_web::rt::time::Sleep">Sleep</a></div><div class="desc docblock-short">Future returned by <a href="fn.sleep.html" title="fn actix_web::rt::time::sleep"><code>sleep</code></a> and <a href="fn.sleep_until.html" title="fn actix_web::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_web::rt::time::Timeout">Timeout</a></div><div class="desc docblock-short">Future returned by <a href="fn.timeout.html" title="fn actix_web::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_web::rt::time::interval">interval</a></div><div class="desc docblock-short">Creates new <a href="struct.Interval.html" title="struct actix_web::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_web::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_web::rt::time::interval_at">interval_at</a></div><div class="desc docblock-short">Creates new <a href="struct.Interval.html" title="struct actix_web::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_web::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_web::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_web::rt::time::sleep_until">sleep_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_web::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_web/rt/time/sidebar-items.js
Normal file
1
actix_web/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"]};
|
107
actix_web/rt/time/struct.Instant.html
Normal file
107
actix_web/rt/time/struct.Instant.html
Normal file
File diff suppressed because one or more lines are too long
150
actix_web/rt/time/struct.Interval.html
Normal file
150
actix_web/rt/time/struct.Interval.html
Normal file
File diff suppressed because one or more lines are too long
158
actix_web/rt/time/struct.Sleep.html
Normal file
158
actix_web/rt/time/struct.Sleep.html
Normal file
File diff suppressed because one or more lines are too long
123
actix_web/rt/time/struct.Timeout.html
Normal file
123
actix_web/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