Skip to main content

prepare_network_change

Function prepare_network_change 

pub async fn prepare_network_change<F, T, E, R>(
    gate: Option<&Semaphore>,
    timeout: Duration,
    prepare: impl FnOnce() -> F,
    finish: impl FnOnce(T) -> Result<R, Box<dyn Error + Sync + Send>>,
) -> Result<R, Box<dyn Error + Sync + Send>>
where F: Future<Output = Result<T, E>>, E: Into<Box<dyn Error + Sync + Send>>,
Available on crate feature net only.
Expand description

Prepare work in response to a network change within a bounded time.

The optional gate bounds concurrent preparations; waiting for it does not consume timeout, and prepare is only called once admitted. The permit is held until finish has consumed the prepared value, so that value is applied before another preparation starts. Dropping the future cancels both.