blocking.Runtime.try_run
Rust
- Python Unavailable
- TypeScript Unavailable
- Rust
- Go Unavailable
- Java Unavailable
- .NET Unavailable
- C++ Unavailable
- Swift Unavailable
- Module
- blocking
- Declared in
- Runtime
- Package
- libtmux
- Source
- crates/libtmux/src/blocking.rs
-
Run one future to completion, or say why it cannot be run here.
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#, or a helper written for a script and later called from an async test.Errors
Returns
Error::RuntimeNestedwhen 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
runwould 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);
0 declared, 0 inherited