SelfDestructingCompletion
public class SelfDestructingCompletion<Param>
A class that wraps a completion block and makes sure it can only be completed once.
To be sure that the completion block is not called by someone else, you should name the variable holding the instance of this class with the same name of the completion block that was passed as a parameters.
Main usecase is for completing immediately something that is cancelled, without the need to add more logic to avoid duplicate call of the completion.
-
The underlying completion block type.
Declaration
Swift
public typealias Completion = (Param) -> Void -
Creates a new instance wrapping the given completion block.
Declaration
Swift
public init(completion: @escaping Completion)Parameters
completionThe block to invoke once when
complete(result:)is called. -
Invokes the wrapped completion block with
resultand clears it so it cannot be called again.Declaration
Swift
public func complete(result: Param)
View on GitHub