Lines Matching full:runtime
1 use crate::runtime::blocking::BlockingPool;
2 use crate::runtime::scheduler::CurrentThread;
3 use crate::runtime::{context, EnterGuard, Handle};
10 use crate::runtime::Builder;
11 use crate::runtime::scheduler::MultiThread;
14 use crate::runtime::scheduler::MultiThreadAlt;
18 /// The Tokio runtime.
20 /// The runtime provides an I/O driver, task scheduler, [timer], and
23 /// Instances of `Runtime` can be created using [`new`], or [`Builder`].
31 /// Shutting down the runtime is done by dropping the value, or calling
34 /// Tasks spawned through [`Runtime::spawn`] keep running until they yield.
38 /// Blocking functions spawned through [`Runtime::spawn_blocking`] keep running
51 /// Once the runtime has been dropped, any outstanding I/O resources bound to
57 /// There are several ways to establish shared access to a Tokio runtime:
59 /// * Using an <code>[Arc]\<Runtime></code>.
61 /// * Entering the runtime context.
63 /// Using an <code>[Arc]\<Runtime></code> or [`Handle`] allows you to do various
64 /// things with the runtime such as spawning new tasks or entering the runtime
66 /// to the same runtime. By passing clones into different tasks or threads, you
67 /// will be able to access the runtime from those tasks or threads.
69 /// The difference between <code>[Arc]\<Runtime></code> and [`Handle`] is that
70 /// an <code>[Arc]\<Runtime></code> will prevent the runtime from shutting down,
72 /// runtime happens when the destructor of the `Runtime` object runs.
75 /// ownership of the `Runtime` type. When using an <code>[Arc]\<Runtime></code>,
79 /// The runtime context is entered using the [`Runtime::enter`] or
81 /// current runtime. Whenever you are inside the runtime context, methods such
82 /// as [`tokio::spawn`] will use the runtime whose context you are inside.
92 /// [`shutdown_background`]: method@Runtime::shutdown_background
93 /// [`shutdown_timeout`]: method@Runtime::shutdown_timeout
95 pub struct Runtime { struct
99 /// Handle to runtime, also contains driver handles
106 /// The flavor of a `Runtime`. argument
108 /// This is the return type for [`Handle::runtime_flavor`](crate::runtime::Handle::runtime_flavor()…
121 /// The runtime scheduler is either a multi-thread or a current-thread executor.
136 impl Runtime { impl
141 ) -> Runtime { in from_parts() argument
142 Runtime { in from_parts()
150 /// Creates a new runtime instance with default configuration values.
157 /// configuration is necessary, the [runtime builder] may be used.
163 /// Creating a new `Runtime` with default configuration values.
166 /// use tokio::runtime::Runtime;
168 /// let rt = Runtime::new()
171 /// // Use the runtime...
177 /// [runtime builder]: crate::runtime::Builder
180 pub fn new() -> std::io::Result<Runtime> {
185 /// Returns a handle to the runtime's spawner.
187 /// The returned handle can be used to spawn tasks that run on this runtime, and can
190 /// Calling [`Handle::block_on`] on a handle to a `current_thread` runtime is error-prone.
196 /// use tokio::runtime::Runtime;
198 /// let rt = Runtime::new()
209 /// Spawns a future onto the Tokio runtime.
211 /// This spawns the given future onto the runtime's executor, usually a
226 /// use tokio::runtime::Runtime;
229 /// // Create the runtime
230 /// let rt = Runtime::new().unwrap();
232 /// // Spawn a future onto the runtime
252 /// use tokio::runtime::Runtime;
255 /// // Create the runtime
256 /// let rt = Runtime::new().unwrap();
258 /// // Spawn a blocking function onto the runtime
272 /// Runs a future to completion on the Tokio runtime. This is the
273 /// runtime's entry point.
277 /// which the future spawns internally will be executed on the runtime.
289 /// to run within the io driver and timer context of the overall runtime.
313 /// use tokio::runtime::Runtime;
315 /// // Create the runtime
316 /// let rt = Runtime::new().unwrap();
341 crate::runtime::task::Id::next().as_u64(), in block_on()
355 /// Enters the runtime context.
368 /// use tokio::runtime::Runtime;
378 /// let rt = Runtime::new().unwrap();
391 /// Shuts down the runtime, waiting for at most `duration` for all spawned
394 /// See the [struct level documentation](Runtime#shutdown) for more details.
399 /// use tokio::runtime::Runtime;
406 /// let runtime = Runtime::new().unwrap();
408 /// runtime.block_on(async move {
414 /// runtime.shutdown_timeout(Duration::from_millis(100));
423 /// Shuts down the runtime, without waiting for any spawned work to stop.
425 /// This can be useful if you want to drop a runtime from within another runtime.
426 /// Normally, dropping a runtime will block indefinitely for spawned blocking tasks
428 /// By calling `shutdown_background()`, you can drop the runtime from such a context.
434 /// See the [struct level documentation](Runtime#shutdown) for more details.
439 /// use tokio::runtime::Runtime;
442 /// let runtime = Runtime::new().unwrap();
444 /// runtime.block_on(async move {
445 /// let inner_runtime = Runtime::new().unwrap();
457 impl Drop for Runtime { implementation
462 // runtime are dropped inside the runtime's context. in drop()
469 // already in the runtime's context. in drop()
475 // already in the runtime's context. in drop()
483 impl Runtime { impl
485 pub fn metrics(&self) -> crate::runtime::RuntimeMetrics {