CancellableGuarantee

public class CancellableGuarantee<T> : CancellableThenable

A CancellableGuarantee is a functional abstraction around an asynchronous operation that can be cancelled but cannot error.

When a cancellable guarantee is cancelled any associated tasks are cancelled but the chain completes successfully. In this situation the guarantee would successfully resolve with whatever value the task returns after being cancelled – perhaps an error, nil, an empty string, or a zero length array. Alternatively, the cancelValue optional parameter explicitly specifies a value to use when the guarantee is cancelled.

See

Thenable
  • Delegate guarantee for this CancellableGuarantee

    Declaration

    Swift

    public var guarantee: Guarantee<T>
  • U

    Type of the delegate thenable

    Declaration

    Swift

    public typealias U = Guarantee<T>
  • Delegate thenable for this CancellableGuarantee

    Declaration

    Swift

    public var thenable: U { get }
  • CancelContext associated with this CancellableGuarantee

    Declaration

    Swift

    public var cancelContext: CancelContext
  • Tracks the cancel items for this CancellableGuarantee. These items are removed from the associated CancelContext when the guarantee resolves.

    Declaration

    Swift

    public var cancelItemList: CancelItemList
  • Override value to use for resolution after the CancellableGuarantee is cancelled. If nil (default) then do not override the resolved value when the CancellableGuarantee is cancelled.

    Declaration

    Swift

    public let cancelValue: T?
  • Initialize a pending CancellableGuarantee that can be resolved with the provided closure’s parameter.

    Declaration

    Swift

    public convenience init(task: CancellableTask? = nil, cancelValue: T? = nil, resolver body: ((T) -> Void) -> Void)

    Parameters

    task

    cancellable task

    cancelValue

    optional override value to use when cancelled

    resolver

    invoked to resolve the CancellableGuarantee

  • Declaration

    Swift

    public class func pending(cancelValue: T? = nil) -> (guarantee: CancellableGuarantee<T>, resolve: (T) -> Void)

    Parameters

    cancelValue

    optional override value to use when cancelled

    Return Value

    a tuple of a pending CancellableGuarantee and a function that resolves it.

  • Declaration

    Swift

    public class func valueCC(_ value: T, cancelValue: T? = nil) -> CancellableGuarantee<T>

    Parameters

    cancelValue

    optional override value to use when cancelled

    Return Value

    a CancellableGuarantee sealed with the provided value.

  • Internal function required for Thenable conformance.

    Declaration

    Swift

    public func pipe(to: @escaping (PromiseKit.Result<T>) -> Void)
  • Declaration

    Swift

    public var result: PromiseKit.Result<T>? { get }

    Return Value

    The current Result for this cancellable guarantee.

  • CancellableGuarantee<[T]> => T -> CancellableGuarantee<V> => CancellableGuarantee<[V]>

    let context = firstly {
        .valueCC([1,2,3])
    }.thenMap {
        .value($0 * 2)
    }.done {
        // $0 => [2,4,6]
    }.cancelContext
    
    //…
    
    context.cancel()
    

    Declaration

    Swift

    func thenMap<V>(on: DispatchQueue? = conf.Q.map, flags: DispatchWorkItemFlags? = nil, cancelValue: [V]? = nil, _ transform: @escaping(T.Iterator.Element) -> CancellableGuarantee<V>) -> CancellableGuarantee<[V]>