Skip to main content

subscribe_with_context

Function subscribe_with_context 

Source
pub fn subscribe_with_context<'or_sub, T, E, OR, D, M, F>(
    observer: OR,
    model: M,
    builder: F,
) -> Subscription<Disposal<'or_sub, D>>
where T: MaybeSend + 'or_sub, E: MaybeSend + 'or_sub, OR: MaybeSend + 'or_sub, D: Disposable, M: MaybeSend + 'or_sub, F: FnOnce(SubscriptionContext<T, E, OR, M>) -> Subscription<D>,
Expand description

Creates a subscription backed by a shared, serialized context containing the downstream observer and a mutable model.

The context does not own the source subscription: the caller’s subscription is chained after the context’s disposal, so the source is disposed only once downstream drops the returned subscription. Use this when the context can only terminate from inside the source’s own on_termination — directly, or in a continuation of it, such as a scheduler task that delivers a termination the source had already parked in the model. The source is then finished by the time the context terminates, so owning it would buy nothing.

When the context can instead terminate while the source is still active — from a notifier, from a scheduler task, or from another source of a multi-source operator — use subscribe_with_context_owning_source so that the source is disposed on termination.