Skip to content

Latest commit

 

History

History
38 lines (27 loc) · 1.38 KB

TraitPublishers-PreventCancellation.md

File metadata and controls

38 lines (27 loc) · 1.38 KB

TraitPublishers.PreventCancellation

TraitPublishers.PreventCancellation prevents its upstream maybe or single publisher from being cancelled.

struct PreventCancellation<Upstream: MaybePublisher>: MaybePublisher {
    /// The upstream publisher
    let upstream: Upstream
    
    /// Creates a `PreventCancellation` publisher
    init(upstream: Upstream)
}

Usage

let upstreamPublisher = ... // some maybe or single publisher
let publisher = upstreamPublisher.preventCancellation()

This publisher produces the same element and completion as its upstream publisher. If it is cancelled, upstream proceeds to completion nevertheless (and its element and completion are left unhandled).

fireAndForget()

When you want to subscribe to a publisher, and let it proceed to completion without handling its output and completion, you can use the fireAndForget subscription method. fireAndForget is available on maybe publishers when Output is Never. You can use ignoreOutput() in order to get such a Never publisher:

publisher.ignoreOutput().fireAndForget() // Available if Failure is Never
publisher.ignoreOutput().fireAndForgetIgnoringFailure()