expression

Stop admitting semaphore work

Close admission permanently for this semaphore. Pending and future acquisitions fail; previously issued permits remain valid until released. Coordinate with active work rather than treating closure as automatic cancellation. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true true Common mistake: Assuming close aborts the tasks that already hold permits.

Formal Syntax & Structure

rust syntaxrust
sem.close(); sem.acquire().await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let sem = tokio::sync::Semaphore::new(1);    let permit = sem.acquire().await.unwrap();    sem.close();    drop(permit);    println!("{} {}", sem.is_closed(), sem.acquire().await.is_err());}
Rust Reference