with_timeout

Function with_timeout 

Source
pub async fn with_timeout<T, F>(timeout: Duration, future: F) -> T
where F: Future<Output = T>,
Expand description

Run an async function with a timeout.

§Panics

Panics if the future does not complete within the timeout.

§Example

use mcpkit_testing::async_helpers::with_timeout;
use std::time::Duration;

#[tokio::test]
async fn test_with_timeout() {
    let result = with_timeout(Duration::from_secs(1), async {
        "hello"
    }).await;
    assert_eq!(result, "hello");
}