Skip to main content

race_command_with_publication

Function race_command_with_publication 

Source
pub async fn race_command_with_publication<C, F, R>(
    sender: Arc<RwLock<UnboundedSender<C>>>,
    connect: F,
    command: impl FnOnce() -> C + Send + 'static,
    active: impl Fn() -> bool,
) -> R
where C: Send + 'static, F: Future<Output = R>,
Expand description

Connects while injecting a command immediately after the shared sender becomes available.

command constructs the command after acquiring the newly published sender. The sender must use Tokio’s fair read/write lock. This function holds a reader until connect queues its publication writer, then queues the command’s reader behind it. The reader’s waker sends the command synchronously during publication, before connect can continue past releasing the writer. No scheduler timing or sleep is required.

§Panics

Panics if connection or publication takes more than five seconds, connect finishes before publication, active is true before publication, or the command cannot enter the new channel.