Skip to main content

detect_blocking

Function detect_blocking 

Source
pub async fn detect_blocking<F, T>(
    name: impl Into<String>,
    max_no_yield: Duration,
    fut: F,
) -> (CheckResult, T)
where F: Future<Output = T>,
Available on crate feature block-detect only.
Expand description

Wrap a future and emit a CheckResult flagging suspected blocking calls inside it.

The wrapper measures the wall-clock duration between every poll’s entry and the immediate-following return. If any single poll exceeds max_no_yield, the verdict is Warn (Warning) with a blocking_suspected tag.

§Example

use dev_async::blocking::detect_blocking;
use std::time::Duration;

let (check, _value) = detect_blocking(
    "user_op",
    Duration::from_millis(50),
    async {
        // ... possibly-blocking code ...
        42
    },
).await;
assert!(check.has_tag("async"));