Core Library0.xAPI Reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

Rust API

method libtmux-rs latest

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
pub async fn with_channel_lock<T, E>( &self, channel: &str, operation: impl AsyncFnOnce(&Self) -> Result<T, E>, ) -> Result<T, crate::ScopeError<T, E>>

Description#

Self::lock_channel() and Self::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::Creation when tmux refuses the lock or the lock runs out of time, Operation when the body fails, and ScopeError::Cleanup when 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?;
Type parameters
Parameters
Esc

Type to search.

Reference previewOpen reference