Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-rs latest

Runtime.try_run

Run one future to completion, or say why it cannot be run here.

Source and package
Qualified name
libtmux::blocking::Runtime::try_run
Module
blocking
Declared in
Runtime
Package
libtmux
Source
crates/libtmux/src/blocking.rs
pub fn try_run<F: Future>(&self, future: F) -> Result< F::Output, Error >

Description#

Same as run(), except that being inside an async context is returned rather than raised. This exists because the callers this module is for are the ones most likely to hit it: a script that grows a #[tokio::main], or a helper written for a script and later called from an async test.

Errors

Returns Error::RuntimeNested when called from inside an async context. Await the future directly there.

Examples#

Outside an async context it runs the future and gives back its value:

use libtmux::blocking::Runtime;
let runtime = Runtime::new()?;
let answer = runtime.try_run(async { 2 + 2 })?;
assert_eq!(answer, 4);

Inside one it says so, where run() would panic:

use libtmux::{Error, ErrorKind};
use libtmux::blocking::Runtime;
let runtime = Runtime::new()?;
let nested = runtime.run(async { runtime.try_run(async { 2 + 2 }) });
assert!(matches!(nested, Err(Error::RuntimeNested)));
assert_eq!(nested.unwrap_err().kind(), ErrorKind::InvalidInput);
Type parameters
  • F #

    Bound Future

Parameters
Esc

Type to search.

Reference previewOpen reference