blob: 559b8a1c58dce4c842b3f1f8ea213061d0b055fe [file] [log] [blame]
<!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="Execute trait is used to execute task in background."><title>Execute in opendal_core - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="opendal_core" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (be0ade2b6 2025-10-11)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js"><script src="../static.files/storage-e2aeef58.js"></script><script defer="" src="sidebar-items.js"></script><script defer="" src="../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Execute</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../opendal_core/index.html"><img src="/img/external/71c0d8847d34b7f8ce3fd204c652c6f9.svg" alt="logo"></a><h2><a href="../opendal_core/index.html">opendal_<wbr>core</a><span class="version">0.55.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Execute</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#notes-about-timeout-implementation" title="Notes about Timeout Implementation">Notes about Timeout Implementation</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.execute" title="execute">execute</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.timeout" title="timeout">timeout</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Execute-for-()" title="()">()</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate opendal_<wbr>core</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="index.html">opendal_core</a></div><h1>Trait <span class="trait">Execute</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/opendal_core/types/execute/api.rs.html#52-67">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Execute:
<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>
+ <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>
+ 'static {
// Required method
fn <a href="#tymethod.execute" class="fn">execute</a>(&amp;self, f: <a class="type" href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture">BoxedStaticFuture</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;);
// Provided method
fn <a href="#method.timeout" class="fn">timeout</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="type" href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture">BoxedStaticFuture</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;&gt; { ... }
}</code></pre><details class="toggle top-doc" open=""><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Execute trait is used to execute task in background.</p>
<h2 id="notes-about-timeout-implementation"><a class="doc-anchor" href="#notes-about-timeout-implementation">§</a>Notes about Timeout Implementation</h2>
<p>Implementing a correct and elegant timeout mechanism is challenging for us.</p>
<p>The <code>Execute</code> trait must be object safe, allowing us to use <code>Arc&lt;dyn Execute&gt;</code>. Consequently,
we cannot introduce a generic type parameter to <code>Execute</code>. We utilize [<code>RemoteHandle</code>] to
implement the <a href="trait.Execute.html#tymethod.execute" title="method opendal_core::Execute::execute"><code>Execute::execute</code></a> method. [<code>RemoteHandle</code>] operates by transmitting
<code>Future::Output</code> through a channel, enabling the spawning of <a href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture"><code>BoxedStaticFuture&lt;()&gt;</code></a>.</p>
<p>However, for timeouts, we need to spawn a future that resolves after a specified duration.
Simply wrapping the future within another timeout future is not feasible because if the timeout
is reached and the original future has not completed, it will be dropped—causing any held <code>Task</code>
to panic.</p>
<p>As an alternative solution, we developed a <code>timeout</code> API. Users of the <code>Executor</code> should invoke
this API when they require a timeout and combine it with their own futures using
[<code>futures::select</code>].</p>
<p>This approach may seem inelegant but it allows us flexibility without being tied specifically
to the Tokio runtime.</p>
<p>PLEASE raising an issue if you have a better solution.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open=""><summary><section id="tymethod.execute" class="method"><a class="src rightside" href="../src/opendal_core/types/execute/api.rs.html#59">Source</a><h4 class="code-header">fn <a href="#tymethod.execute" class="fn">execute</a>(&amp;self, f: <a class="type" href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture">BoxedStaticFuture</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;)</h4></section></summary><div class="docblock"><p>Execute async task in background.</p>
<h5 id="behavior"><a class="doc-anchor" href="#behavior">§</a>Behavior</h5>
<ul>
<li>Implementor MUST manage the executing futures and keep making progress.</li>
<li>Implementor MUST NOT drop futures until it’s resolved.</li>
</ul>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open=""><summary><section id="method.timeout" class="method"><a class="src rightside" href="../src/opendal_core/types/execute/api.rs.html#64-66">Source</a><h4 class="code-header">fn <a href="#method.timeout" class="fn">timeout</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="type" href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture">BoxedStaticFuture</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Return a future that will be resolved after the given timeout.</p>
<p>Default implementation returns None.</p>
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Execute-for-()" class="impl"><a class="src rightside" href="../src/opendal_core/types/execute/api.rs.html#69-73">Source</a><a href="#impl-Execute-for-()" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Execute.html" title="trait opendal_core::Execute">Execute</a> for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a></h3></section></summary><div class="impl-items"><section id="method.execute" class="method trait-impl"><a class="src rightside" href="../src/opendal_core/types/execute/api.rs.html#70-72">Source</a><a href="#method.execute" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.execute" class="fn">execute</a>(&amp;self, _: <a class="type" href="raw/type.BoxedStaticFuture.html" title="type opendal_core::raw::BoxedStaticFuture">BoxedStaticFuture</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>&gt;)</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Execute-for-TokioExecutor" class="impl"><a class="src rightside" href="../src/opendal_core/types/execute/executors/tokio_executor.rs.html#25-30">Source</a><a href="#impl-Execute-for-TokioExecutor" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Execute.html" title="trait opendal_core::Execute">Execute</a> for <a class="struct" href="executors/struct.TokioExecutor.html" title="struct opendal_core::executors::TokioExecutor">TokioExecutor</a></h3><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>executors-tokio</code></strong> only.</div></span></section></div><script src="../trait.impl/opendal_core/types/execute/api/trait.Execute.js" data-ignore-extern-crates="std" async=""></script></section></div></main></body></html>