Server.with_channel_lock
Hold a wait-for channel for the length of an operation.
Source and package
- Qualified name
-
libtmux::server:: Server:: with _channel _lock - Module
- server
- Declared in
Server- Package
- libtmux
- Source
- crates/libtmux/src/server/channels.rs
-
Description#
Self::lock_channel()andSelf::unlock_channel()as a pair, so a locker that returns early, fails, or panics still releases the channel: a lock left held wedges every later locker on the server.Errors
crate::ScopeError::Creationwhen tmux refuses the lock or the lock runs out of time,Operationwhen the body fails, andScopeError::Cleanupwhen the unlock fails after the body succeeded.Cancel safety
Nothing is left held by a drop. The lock is taken and released in tasks of their own, so a scope dropped while its lock is still queued unlocks once tmux grants it, as
Self::lock_channel()describes.Examples#
let guard = libtmux::test::TestServer::new().await?;let server = guard.server();let count = server.with_channel_lock("deploy", async |server| {Ok::<_, libtmux::Error>(server.sessions().await?.len())}).await?;// The channel is free again, so the next locker is not blocked.server.lock_channel("deploy").await?;server.unlock_channel("deploy").await?;guard.shutdown().await?;