Lines Matching full:runtime
2 use crate::runtime;
3 use crate::runtime::{context, scheduler, RuntimeFlavor};
5 /// Handle to the runtime.
8 /// obtained using the [`Runtime::handle`] method.
10 /// [`Runtime::handle`]: crate::runtime::Runtime::handle()
18 use crate::runtime::task::JoinHandle;
25 /// Runtime context guard.
27 /// Returned by [`Runtime::enter`] and [`Handle::enter`], the context guard exits
28 /// the runtime context on drop.
30 /// [`Runtime::enter`]: fn@crate::runtime::Runtime::enter
39 /// Enters the runtime context. This allows you to construct types that must
53 /// use tokio::runtime::Runtime;
55 /// let rt = Runtime::new().unwrap();
67 /// use tokio::runtime::Runtime;
69 /// let rt1 = Runtime::new().unwrap();
70 /// let rt2 = Runtime::new().unwrap();
92 /// Returns a `Handle` view over the currently running `Runtime`.
96 /// This will panic if called outside the context of a Tokio runtime. That means that you must
97 … /// call this on one of the threads **being run by the runtime**, or from a thread with an active
103 /// This can be used to obtain the handle of the surrounding runtime from an async
104 /// block or function running on that runtime.
108 /// # use tokio::runtime::Runtime;
110 /// # let rt = Runtime::new().unwrap();
112 /// use tokio::runtime::Handle;
117 /// println!("now running in the existing Runtime");
124 /// // This next line would cause a panic because we haven't entered the runtime
143 /// Returns a Handle view over the currently running Runtime
145 /// Returns an error if no Runtime has been started
154 /// Spawns a future onto the Tokio runtime.
156 /// This spawns the given future onto the runtime's executor, usually a
171 /// use tokio::runtime::Runtime;
174 /// // Create the runtime
175 /// let rt = Runtime::new().unwrap();
176 /// // Get a handle from this runtime
179 /// // Spawn a future onto the runtime using the handle
200 /// use tokio::runtime::Runtime;
203 /// // Create the runtime
204 /// let rt = Runtime::new().unwrap();
205 /// // Get a handle from this runtime
208 /// // Spawn a blocking function onto the runtime using the handle
222 /// Runs a future to completion on this `Handle`'s associated `Runtime`.
226 /// the future spawns internally will be executed on the runtime.
228 /// When this is used on a `current_thread` runtime, only the
229 /// [`Runtime::block_on`] method can drive the IO and timer drivers, but the
231 /// this method on a current_thread runtime, anything that relies on IO or
233 /// [`Runtime::block_on`] on the same runtime.
235 /// # If the runtime has been shut down
237 /// If the `Handle`'s associated `Runtime` has been shut down (through
238 /// [`Runtime::shutdown_background`], [`Runtime::shutdown_timeout`], or by
241 /// panic. Runtime independent futures will run as normal.
247 /// runtime that has been shut down.
252 /// use tokio::runtime::Runtime;
254 /// // Create the runtime
255 /// let rt = Runtime::new().unwrap();
257 /// // Get a handle from this runtime
269 /// use tokio::runtime::Handle;
285 /// [`Runtime::block_on`]: fn@crate::runtime::Runtime::block_on
286 /// [`Runtime::shutdown_background`]: fn@crate::runtime::Runtime::shutdown_background
287 /// [`Runtime::shutdown_timeout`]: fn@crate::runtime::Runtime::shutdown_timeout
307 // Enter the runtime context. This sets the current driver handles and in block_on()
308 // prevents blocking an existing runtime. in block_on()
320 let id = crate::runtime::task::Id::next(); in spawn_named()
334 /// Returns the flavor of the current `Runtime`.
339 /// use tokio::runtime::{Handle, RuntimeFlavor};
348 /// use tokio::runtime::{Handle, RuntimeFlavor};
366 /// Returns the [`Id`] of the current `Runtime`.
371 /// use tokio::runtime::Handle;
375 /// println!("Current runtime id: {}", Handle::current().id());
384 /// [`Id`]: struct@crate::runtime::Id
385 pub fn id(&self) -> runtime::Id {
399 use crate::runtime::RuntimeMetrics;
402 /// Returns a view that lets you get information about how the runtime
412 /// Captures a snapshot of the runtime's state.
419 /// This can be used to get call traces of each task in the runtime.
422 /// single blocked runtime thread into an entirely blocked runtime.
425 /// # use tokio::runtime::Runtime;
427 /// # let rt = Runtime::new().unwrap();
429 /// use tokio::runtime::Handle;
500 /// ## Current Thread Runtime Requirements
502 /// On the `current_thread` runtime, task dumps may only be requested
503 /// from *within* the context of the runtime being dumped. Do not, for
504 /// example, await `Handle::dump()` on a different runtime.
511 /// additional runtime overhead, actually calling `Handle::dump` is
512 /// expensive. The runtime must synchronize and pause its workers, then
524 /// another runtime worker is blocked for more than 250ms. This may
525 /// occur if a dump is requested during shutdown, or if another runtime
529 pub async fn dump(&self) -> crate::runtime::Dump {
543 …cheduler::Handle::MultiThreadAlt(_) => panic!("task dump not implemented for this runtime flavor"),
557 let rt = crate::runtime::Builder::new_current_thread().build().unwrap();
567 /// Error returned by `try_current` when no Runtime has been started
586 /// Returns true if the call failed because there is currently no runtime in