pub struct Handle { /* private fields */ }
Expand description
Handle to the runtime
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn current() -> Self
pub fn current() -> Self
Returns a Handle view over the currently running Runtime
§Panic
A Runtime must have been started or this will panic
§Examples
This allows for the current handle to be gotten when running in a #
use tokio::runtime::Handle;
let handle = Handle::current();
handle.spawn(async {
println!("now running in the existing Runtime");
})
Sourcepub fn try_current() -> Result<Self, TryCurrentError>
pub fn try_current() -> Result<Self, TryCurrentError>
Returns a Handle view over the currently running Runtime
Returns an error if no Runtime has been started
Contrary to current
, this never panics
Source§impl Handle
impl Handle
Sourcepub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output> ⓘ
Spawn a future onto the Tokio runtime.
This spawns the given future onto the runtime’s executor, usually a thread pool. The thread pool is then responsible for polling the future until it completes.
See module level documentation for more details.
§Examples
use tokio::runtime::Runtime;
// Create the runtime
let rt = Runtime::new().unwrap();
let handle = rt.handle();
// Spawn a future onto the runtime
handle.spawn(async {
println!("now running on a worker thread");
});
§Panics
This function panics if the spawn fails. Failure occurs if the executor is currently at capacity and is unable to spawn a new future.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Handle
impl !RefUnwindSafe for Handle
impl Send for Handle
impl Sync for Handle
impl Unpin for Handle
impl !UnwindSafe for Handle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)