Lines Matching full:runtime
2 use crate::runtime::blocking::BlockingPool;
3 use crate::runtime::scheduler::CurrentThread;
4 use crate::runtime::{context, EnterGuard, Handle};
13 use crate::runtime::Builder;
14 use crate::runtime::scheduler::MultiThread;
17 use crate::runtime::scheduler::MultiThreadAlt;
21 /// The Tokio runtime.
23 /// The runtime provides an I/O driver, task scheduler, [timer], and
26 /// Instances of `Runtime` can be created using [`new`], or [`Builder`].
34 /// Shutting down the runtime is done by dropping the value, or calling
37 /// Tasks spawned through [`Runtime::spawn`] keep running until they yield.
41 /// Blocking functions spawned through [`Runtime::spawn_blocking`] keep running
54 /// Once the runtime has been dropped, any outstanding I/O resources bound to
60 /// There are several ways to establish shared access to a Tokio runtime:
62 /// * Using an <code>[Arc]\<Runtime></code>.
64 /// * Entering the runtime context.
66 /// Using an <code>[Arc]\<Runtime></code> or [`Handle`] allows you to do various
67 /// things with the runtime such as spawning new tasks or entering the runtime
69 /// to the same runtime. By passing clones into different tasks or threads, you
70 /// will be able to access the runtime from those tasks or threads.
72 /// The difference between <code>[Arc]\<Runtime></code> and [`Handle`] is that
73 /// an <code>[Arc]\<Runtime></code> will prevent the runtime from shutting down,
75 /// runtime happens when the destructor of the `Runtime` object runs.
78 /// ownership of the `Runtime` type. When using an <code>[Arc]\<Runtime></code>,
82 /// The runtime context is entered using the [`Runtime::enter`] or
84 /// current runtime. Whenever you are inside the runtime context, methods such
85 /// as [`tokio::spawn`] will use the runtime whose context you are inside.
96 /// [`shutdown_background`]: method@Runtime::shutdown_background
97 /// [`shutdown_timeout`]: method@Runtime::shutdown_timeout
99 pub struct Runtime { struct
103 /// Handle to runtime, also contains driver handles
110 /// The flavor of a `Runtime`. argument
112 /// This is the return type for [`Handle::runtime_flavor`](crate::runtime::Handle::runtime_flavor()…
126 /// The runtime scheduler is either a multi-thread or a current-thread executor.
141 impl Runtime { impl
146 ) -> Runtime { in from_parts() argument
147 Runtime { in from_parts()
154 /// Creates a new runtime instance with default configuration values.
161 /// configuration is necessary, the [runtime builder] may be used.
167 /// Creating a new `Runtime` with default configuration values.
170 /// use tokio::runtime::Runtime;
172 /// let rt = Runtime::new()
175 /// // Use the runtime...
181 /// [runtime builder]: crate::runtime::Builder
184 pub fn new() -> std::io::Result<Runtime> { in new()
188 /// Returns a handle to the runtime's spawner.
190 /// The returned handle can be used to spawn tasks that run on this runtime, and can
193 /// Calling [`Handle::block_on`] on a handle to a `current_thread` runtime is error-prone.
199 /// use tokio::runtime::Runtime;
201 /// let rt = Runtime::new()
212 /// Spawns a future onto the Tokio runtime.
214 /// This spawns the given future onto the runtime's executor, usually a
229 /// use tokio::runtime::Runtime;
232 /// // Create the runtime
233 /// let rt = Runtime::new().unwrap();
235 /// // Spawn a future onto the runtime
262 /// use tokio::runtime::Runtime;
265 /// // Create the runtime
266 /// let rt = Runtime::new().unwrap();
268 /// // Spawn a blocking function onto the runtime
283 /// Runs a future to completion on the Tokio runtime. This is the
284 /// runtime's entry point.
288 /// which the future spawns internally will be executed on the runtime.
300 /// to run within the io driver and timer context of the overall runtime.
324 /// use tokio::runtime::Runtime;
326 /// // Create the runtime
327 /// let rt = Runtime::new().unwrap();
362 crate::runtime::task::Id::next().as_u64(), in block_on_inner()
376 /// Enters the runtime context.
389 /// use tokio::runtime::Runtime;
400 /// let rt = Runtime::new().unwrap();
416 /// Shuts down the runtime, waiting for at most `duration` for all spawned
419 /// See the [struct level documentation](Runtime#shutdown) for more details.
424 /// use tokio::runtime::Runtime;
431 /// let runtime = Runtime::new().unwrap();
433 /// runtime.block_on(async move {
439 /// runtime.shutdown_timeout(Duration::from_millis(100));
448 /// Shuts down the runtime, without waiting for any spawned work to stop.
450 /// This can be useful if you want to drop a runtime from within another runtime.
451 /// Normally, dropping a runtime will block indefinitely for spawned blocking tasks
453 /// By calling `shutdown_background()`, you can drop the runtime from such a context.
459 /// See the [struct level documentation](Runtime#shutdown) for more details.
464 /// use tokio::runtime::Runtime;
467 /// let runtime = Runtime::new().unwrap();
469 /// runtime.block_on(async move {
470 /// let inner_runtime = Runtime::new().unwrap();
480 /// Returns a view that lets you get information about how the runtime
482 pub fn metrics(&self) -> crate::runtime::RuntimeMetrics { in metrics()
488 impl Drop for Runtime { implementation
493 // runtime are dropped inside the runtime's context. in drop()
500 // already in the runtime's context. in drop()
506 // already in the runtime's context. in drop()
513 impl std::panic::UnwindSafe for Runtime {} implementation
515 impl std::panic::RefUnwindSafe for Runtime {} implementation