PromiseInvalidationToken
public struct PromiseInvalidationToken : CustomStringConvertible, CustomDebugStringConvertible
extension PromiseInvalidationToken: Hashable
An invalidation token that can be used to cancel callbacks registered to a Promise.
-
Creates and returns a new
PromiseInvalidationToken.Declaration
Swift
public init(invalidateOnDeinit: Bool = true)Parameters
invalidateOnDeinitThe default value of
truemeans the token will automatically be invalidated when it deinits. Iffalseit won’t invalidate unless you explicitly callinvalidate(). This is primarily useful in conjunction withrequestCancelOnInvalidate(_:)so you don’t have to cancel your promises when the object that owns the invalidation token deinits. -
Invalidates the token and cancels any associated promises.
After invoking this method, all
Promisecallbacks registered with this token will be suppressed. Any callbacks whose return value is used for a subsequent promise (e.g. withmap(on:token:_:)) will result in a cancelled promise instead if the callback would otherwise have been executed.In addition, any promises that have been registered with
requestCancelOnInvalidate(_:)will be requested to cancel.Declaration
Swift
public func invalidate() -
Cancels any associated promises without invalidating the token.
After invoking this method, any promises that have been registered with
requestCancelOnInvalidate(_:)will be requested to cancel.Declaration
Swift
public func cancelWithoutInvalidating() -
Registers an
ObjCPromiseto be requested to cancel automatically when the token is invalidated.Declaration
Swift
public func requestCancelOnInvalidate<V, E>(_ promise: ObjCPromise<V, E>) where V : AnyObject, E : AnyObject -
Invalidates the token whenever another token is invalidated.
When the given other token is invalidated, the receiver will also be invalidated. This allows you to build trees of tokens for fine-grained cancellation control while still allowing for the ability to cancel a lot of promises from a single token.
Note
Chained invalidation is a permanent relationship with no way to un-chain it later. Invalidating
tokenmultiple times will invalidate the receiver every time.Remark
By using chained invalidation it’s possible to construct a scenario wherein you respond to cancellation of a promise associated with the parent token by immediately constructing a new promise using a child token, prior to the child token being invalidated due to the parent token’s invalidation. This is a rather esoteric case.
Important
Do not introduce any cycles into the invalidation chain, as this will produce an infinite loop upon invalidation.
Declaration
Swift
public func chainInvalidation(from token: PromiseInvalidationToken, includingCancelWithoutInvalidating: Bool = true)Parameters
tokenAnother token that, when invalidated, will cause the current token to be invalidated as well.
includingCancelWithoutInvalidatingThe default value of
truemeans calls totoken.cancelWithoutInvalidating()will similarly callcancelWithoutInvalidating()on the current token. -
Declaration
Swift
public var description: String { get } -
Declaration
Swift
public var debugDescription: String { get }
-
Returns a Boolean value indicating whether two values are equal.
Equality is the inverse of inequality. For any values
aandb,a == bimplies thata != bisfalse.Declaration
Swift
public static func == (lhs: PromiseInvalidationToken, rhs: PromiseInvalidationToken) -> BoolParameters
lhsA value to compare.
rhsAnother value to compare.
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
View on GitHub
PromiseInvalidationToken Structure Reference