Elektrine lite

← Feed

@dani@fosstodon.org

2026-09-23 20:09 UTC

TIL that in #rust, writing this: let _ = semaphore.acquire().await?; Is a terrible idea, if you want to use a semaphore to limit the number of concurrent tasks, because the semaphore is automatically dropped, as the binding is unused. To fix it: let foo = semaphore.acquire().await?; So the compiler will only drop the semaphore when variable foo goes out of scope.

Replies (1)

  • @AMDmi3@fosstodon.org 2026-09-23 20:14

    @dani@fosstodon.org `let _foo = ` to be precise, to indicate both that it should not be immediately dropped, and that the value is expected be unused.

    Open ##5285057