FireAndForget
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public struct FireAndForget<IgnoringOutput> : Publisher
Fire And Forget is a publisher for when you don’t care about the output of certain async operation. It’s important to notice that this operation can’t fail. If you want to also ignore the failure, then you can catchErrors and return nil in the proper init. It may complete successfully when task is done.
-
Output type we are ignoring. It matches the FireAndForget generic parameter, so we can ignore anything we want.
Declaration
Swift
public typealias Output = IgnoringOutput
-
We’re only able to ignore the output, not the failure, so it’s important that this publisher never fails. To ignore also the failure path please use the init with catchErrors parameter and return nil from it.
Declaration
Swift
public typealias Failure = Never
-
Init a FireAndForget publisher by providing a closure with the operation to execute and ignore the output.
Declaration
Swift
public init(_ operation: @escaping () -> Void)
Parameters
operation
any operation you want to run async and ignore the result
-
Init a FireAndForget publisher by providing a closure with the operation to execute and ignore the output.
Declaration
Swift
public init<S>(scheduler: S, _ operation: @escaping () -> Void) where S : Scheduler
Parameters
operation
any operation you want to run async and ignore the result
-
Init a FireAndForget publisher by providing an upstream that never fails so we can simply ignore its output
Declaration
Swift
public init<P>(_ upstream: P) where P : Publisher, P.Failure == Never
Parameters
upstream
any publisher that never fails
-
Init a FireAndForget publisher by providing an upstream that could fail, as well as a catchErrors function to ensure that FireAndForget can’t itself fail. You can safely return nil from catchErrors. Otherwise outputs sent from catch errors will NOT be ignored, only those from the happy path.
Declaration
Swift
public init<P>(_ upstream: P, catchErrors: @escaping (P.Failure) -> IgnoringOutput?) where P : Publisher
-
Attaches the specified subscriber to this publisher.
Implementations of
Publisher
must implement this method.Declaration
Parameters
subscriber
The subscriber to attach to this
Publisher
, after which it can receive values.