trait.Notify.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `Notify` trait in crate `futures`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, Notify">
  9. <title>futures::executor::Notify - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../../main.css" id="themeStyle">
  14. <script src="../../storage.js"></script>
  15. </head>
  16. <body class="rustdoc trait">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Trait Notify</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.notify">notify</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.clone_id">clone_id</a><a href="#method.drop_id">drop_id</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><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></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <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'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../../src/futures/task_impl/mod.rs.html#390-444' title='goto source code'>[src]</a></span></h1>
  50. <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> {
  51. fn <a href='#tymethod.notify' class='fnname'>notify</a>(&amp;self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>);
  52. fn <a href='#method.clone_id' class='fnname'>clone_id</a>(&amp;self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> { ... }
  53. <div class='item-spacer'></div> fn <a href='#method.drop_id' class='fnname'>drop_id</a>(&amp;self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) { ... }
  54. }</pre><div class='docblock'><p>A trait which represents a sink of notifications that a future is ready to
  55. make progress.</p>
  56. <p>This trait is provided as an argument to the <code>Spawn::*_notify</code> family of
  57. functions. It's transitively used as part of the <code>Task::notify</code> method to
  58. internally deliver notifications of readiness of a future to move forward.</p>
  59. <p>An instance of <code>Notify</code> has one primary method, <code>notify</code>, which is given a
  60. contextual argument as to what's being notified. This contextual argument is
  61. <em>also</em> provided to the <code>Spawn::*_notify</code> family of functions and can be used
  62. to reuse an instance of <code>Notify</code> across many futures.</p>
  63. <p>Instances of <code>Notify</code> must be safe to share across threads, and the methods
  64. be invoked concurrently. They must also live for the <code>'static</code> lifetime,
  65. not containing any stack references.</p>
  66. </div>
  67. <h2 id='required-methods' class='small-section-header'>
  68. Required Methods<a href='#required-methods' class='anchor'></a>
  69. </h2>
  70. <div class='methods'>
  71. <h3 id='tymethod.notify' class='method'><span id='notify.v' class='invisible'><code>fn <a href='#tymethod.notify' class='fnname'>notify</a>(&amp;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
  72. progress.</p>
  73. <p>Typically this means that the receiver of the notification should
  74. arrange for the future to get poll'd in a prompt fashion.</p>
  75. <p>This method takes an <code>id</code> as an argument which was transitively passed
  76. in from the original call to <code>Spawn::*_notify</code>. This id can be used to
  77. disambiguate which precise future became ready for polling.</p>
  78. <h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
  79. <p>Since <code>unpark</code> may be invoked from arbitrary contexts, it should
  80. endeavor not to panic and to do as little work as possible. However, it
  81. is not guaranteed not to panic, and callers should be wary. If a panic
  82. occurs, that panic may or may not be propagated to the end-user of the
  83. future that you'd otherwise wake up.</p>
  84. </div></div>
  85. <h2 id='provided-methods' class='small-section-header'>
  86. Provided Methods<a href='#provided-methods' class='anchor'></a>
  87. </h2>
  88. <div class='methods'>
  89. <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>(&amp;self, id: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -&gt; <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>
  90. <p>This is called in one of two situations:</p>
  91. <ul>
  92. <li>A <code>Task</code> is being created through <code>task::current</code> while a future is
  93. being polled. In that case the instance of <code>Notify</code> passed in to one
  94. of the <code>poll_*</code> functions is called with the <code>id</code> passed into the same
  95. <code>poll_*</code> function.</li>
  96. <li>A <code>Task</code> is itself being cloned. Each <code>Task</code> contains its own id and a
  97. handle to the <code>Notify</code> behind it, and the task's <code>Notify</code> is used to
  98. clone the internal <code>id</code> to assign to the new task.</li>
  99. </ul>
  100. <p>The <code>id</code> returned here will be stored in the <code>Task</code>-to-be and used later
  101. to pass to <code>notify</code> when the <code>Task::notify</code> function is called on that
  102. <code>Task</code>.</p>
  103. <p>Note that typically this is just the identity function, passing through
  104. the identifier. For more unsafe situations, however, if <code>id</code> is itself a
  105. pointer of some kind this can be used as a hook to &quot;clone&quot; the pointer,
  106. depending on what that means for the specified pointer.</p>
  107. </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>(&amp;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
  108. notify with, and this function is called when the <code>Task</code> is dropped.</p>
  109. <p>This function provides a hook for schemes which encode pointers in this
  110. <code>id</code> argument to deallocate resources associated with the pointer. It's
  111. guaranteed that after this function is called the <code>Task</code> containing this
  112. <code>id</code> will no longer use the <code>id</code>.</p>
  113. </div></div>
  114. <h2 id='implementors' class='small-section-header'>
  115. Implementors<a href='#implementors' class='anchor'></a>
  116. </h2>
  117. <ul class='item-list' id='implementors-list'>
  118. </ul><script type="text/javascript" async
  119. src="../../implementors/futures/executor/trait.Notify.js">
  120. </script></section>
  121. <section id='search' class="content hidden"></section>
  122. <section class="footer"></section>
  123. <aside id="help" class="hidden">
  124. <div>
  125. <h1 class="hidden">Help</h1>
  126. <div class="shortcuts">
  127. <h2>Keyboard Shortcuts</h2>
  128. <dl>
  129. <dt><kbd>?</kbd></dt>
  130. <dd>Show this help dialog</dd>
  131. <dt><kbd>S</kbd></dt>
  132. <dd>Focus the search field</dd>
  133. <dt><kbd></kbd></dt>
  134. <dd>Move up in search results</dd>
  135. <dt><kbd></kbd></dt>
  136. <dd>Move down in search results</dd>
  137. <dt><kbd></kbd></dt>
  138. <dd>Switch tab</dd>
  139. <dt><kbd>&#9166;</kbd></dt>
  140. <dd>Go to active search result</dd>
  141. <dt><kbd>+</kbd></dt>
  142. <dd>Expand all sections</dd>
  143. <dt><kbd>-</kbd></dt>
  144. <dd>Collapse all sections</dd>
  145. </dl>
  146. </div>
  147. <div class="infos">
  148. <h2>Search Tricks</h2>
  149. <p>
  150. Prefix searches with a type followed by a colon (e.g.
  151. <code>fn:</code>) to restrict the search to a given type.
  152. </p>
  153. <p>
  154. Accepted types are: <code>fn</code>, <code>mod</code>,
  155. <code>struct</code>, <code>enum</code>,
  156. <code>trait</code>, <code>type</code>, <code>macro</code>,
  157. and <code>const</code>.
  158. </p>
  159. <p>
  160. Search functions by type signature (e.g.
  161. <code>vec -> usize</code> or <code>* -> vec</code>)
  162. </p>
  163. </div>
  164. </div>
  165. </aside>
  166. <script>
  167. window.rootPath = "../../";
  168. window.currentCrate = "futures";
  169. </script>
  170. <script src="../../main.js"></script>
  171. <script defer src="../../search-index.js"></script>
  172. </body>
  173. </html>