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

    invalidateOnDeinit

    The default value of true means the token will automatically be invalidated when it deinits. If false it won’t invalidate unless you explicitly call invalidate(). This is primarily useful in conjunction with requestCancelOnInvalidate(_:) 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 Promise callbacks registered with this token will be suppressed. Any callbacks whose return value is used for a subsequent promise (e.g. with map(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 a Promise to be requested to cancel automatically when the token is invalidated.

    Declaration

    Swift

    public func requestCancelOnInvalidate<V, E>(_ promise: Promise<V, E>)
  • Registers an ObjCPromise to 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 token multiple 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

    token

    Another token that, when invalidated, will cause the current token to be invalidated as well.

    includingCancelWithoutInvalidating

    The default value of true means calls to token.cancelWithoutInvalidating() will similarly call cancelWithoutInvalidating() on the current token.

  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public var debugDescription: String { get }

Equatable

  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    public static func == (lhs: PromiseInvalidationToken, rhs: PromiseInvalidationToken) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)