On this page
blocking.Runtime.try_run
- 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.[
run]: Self::runErrors
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 [
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);
0 declared, 0 inherited