<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `Notify` trait in crate `futures`.">
<meta name="keywords" content="rust, rustlang, rust-lang, Notify">
<title>futures::executor::Notify - Rust</title>
<link rel="stylesheet" type="text/css" href="../../normalize.css">
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../main.css">
</head>
<body class="rustdoc trait">
<nav class="sidebar">
<p class='location'><a href='../index.html'>futures</a>::<wbr><a href='index.html'>executor</a></p><script>window.sidebarCurrent = {name: 'Notify', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>futures</a>::<wbr><a href='index.html'>executor</a>::<wbr><a class="trait" href=''>Notify</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>−</span>]
</a>
</span><a class='srclink' href='../../src/futures/task_impl/mod.rs.html#379-425' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'>pub trait Notify: <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> {
fn <a href='#tymethod.notify' class='fnname'>notify</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>);
fn <a href='#method.clone_id' class='fnname'>clone_id</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> { ... }
fn <a href='#method.drop_id' class='fnname'>drop_id</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) { ... }
}</pre><div class='docblock'><p>A trait which represents a sink of notifications that a future is ready to
make progress.</p>
<p>This trait is provided as an argument to the <code>Spawn::*_notify</code> family of
functions. It's transitively used as part of the <code>Task::notify</code> method to
internally deliver notifications of readiness of a future to move forward.</p>
<p>An instance of <code>Notify</code> has one primary method, <code>notify</code>, which is given a
contextual argument as to what's being notified. This contextual argument is
<em>also</em> provided to the <code>Spawn::*_notify</code> family of functions and can be used
to reuse an instance of <code>Notify</code> across many futures.</p>
<p>Instances of <code>Notify</code> must be safe to share across threads, and the methods
be invoked concurrently. They must also live for the <code>'static</code> lifetime,
not containing any stack references.</p>
</div>
<h2 id='required-methods'>Required Methods</h2>
<div class='methods'>
<h3 id='tymethod.notify' class='method'><span id='notify.v' class='invisible'><code>fn <a href='#tymethod.notify' class='fnname'>notify</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code></span></h3><div class='docblock'><p>Indicates that an associated future and/or task are ready to make
progress.</p>
<p>Typically this means that the receiver of the notification should
arrange for the future to get poll'd in a prompt fashion.</p>
<p>This method takes an <code>id</code> as an argument which was transitively passed
in from the original call to <code>Spawn::*_notify</code>. This id can be used to
disambiguate which precise future became ready for polling.</p>
</div></div>
<h2 id='provided-methods'>Provided Methods</h2>
<div class='methods'>
<h3 id='method.clone_id' class='method'><span id='clone_id.v' class='invisible'><code>fn <a href='#method.clone_id' class='fnname'>clone_id</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code></span></h3><div class='docblock'><p>This function is called whenever a new copy of <code>id</code> is needed.</p>
<p>This is called in one of two situations:</p>
<ul>
<li>A <code>Task</code> is being created through <code>task::current</code> while a future is
being polled. In that case the instance of <code>Notify</code> passed in to one
of the <code>poll_*</code> functions is called with the <code>id</code> passed into the same
<code>poll_*</code> function.</li>
<li>A <code>Task</code> is itself being cloned. Each <code>Task</code> contains its own id and a
handle to the <code>Notify</code> behind it, and the task's <code>Notify</code> is used to
clone the internal <code>id</code> to assign to the new task.</li>
</ul>
<p>The <code>id</code> returned here will be stored in the <code>Task</code>-to-be and used later
to pass to <code>notify</code> when the <code>Task::notify</code> function is called on that
<code>Task</code>.</p>
<p>Note that typically this is just the identity function, passing through
the identifier. For more unsafe situations, however, if <code>id</code> is itself a
pointer of some kind this can be used as a hook to "clone" the pointer,
depending on what that means for the specified pointer.</p>
</div><h3 id='method.drop_id' class='method'><span id='drop_id.v' class='invisible'><code>fn <a href='#method.drop_id' class='fnname'>drop_id</a>(&self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</code></span></h3><div class='docblock'><p>All instances of <code>Task</code> store an <code>id</code> that they're going to internally
notify with, and this function is called when the <code>Task</code> is dropped.</p>
<p>This function provides a hook for schemes which encode pointers in this
<code>id</code> argument to deallocate resources associated with the pointer. It's
guaranteed that after this function is called the <code>Task</code> containing this
<code>id</code> will no longer use the <code>id</code>.</p>
</div></div>
<h2 id='implementors'>Implementors</h2>
<ul class='item-list' id='implementors-list'>
</ul><script type="text/javascript" async
src="../../implementors/futures/executor/trait.Notify.js">
</script></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>⇤</dt>
<dd>Move up in search results</dd>
<dt>⇥</dt>
<dd>Move down in search results</dd>
<dt>⏎</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "futures";
</script>
<script src="../../jquery.js"></script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>