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
guaranteefor this CancellableGuaranteeDeclaration
Swift
public var guarantee: Guarantee<T> -
Type of the delegate
thenableDeclaration
Swift
public typealias U = Guarantee<T> -
Delegate
thenablefor this CancellableGuaranteeDeclaration
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
CancellableGuaranteethat 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
taskcancellable task
cancelValueoptional override value to use when cancelled
resolverinvoked to resolve the
CancellableGuarantee -
Declaration
Swift
public class func pending(cancelValue: T? = nil) -> (guarantee: CancellableGuarantee<T>, resolve: (T) -> Void)Parameters
cancelValueoptional override value to use when cancelled
Return Value
a tuple of a pending
CancellableGuaranteeand a function that resolves it. -
Declaration
Swift
public class func valueCC(_ value: T, cancelValue: T? = nil) -> CancellableGuarantee<T>Parameters
cancelValueoptional override value to use when cancelled
Return Value
a
CancellableGuaranteesealed with the provided value. -
Internal function required for
Thenableconformance.Declaration
Swift
public func pipe(to: @escaping (PromiseKit.Result<T>) -> Void) -
Declaration
Swift
public var result: PromiseKit.Result<T>? { get }Return Value
The current
Resultfor this cancellable guarantee.
-
Declaration
Swift
@discardableResult func done(on: DispatchQueue? = conf.Q.return, flags: DispatchWorkItemFlags? = nil, cancelValue: T? = nil, _ body: @escaping(T) -> Void) -> CancellableGuarantee<Void> -
Declaration
Swift
func get(on: DispatchQueue? = conf.Q.return, flags: DispatchWorkItemFlags? = nil, cancelValue: T? = nil, _ body: @escaping (T) -> Void) -> CancellableGuarantee<T> -
Declaration
-
Declaration
-
Declaration
-
Declaration
Swift
public func asVoid() -> CancellableGuarantee<Void> -
Blocks this thread, so—you know—don’t call this on a serial thread that any part of your chain may use. Like the main thread for example.
Declaration
Swift
public func wait() throws -> T
-
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]>
-
Initializes a new cancellable guarantee fulfilled with
VoidDeclaration
Swift
public convenience init(context: CancelContext? = nil)Parameters
contextoptional
CancelContextto associate with thisCancellableGuarantee -
Initializes a new cancellable guarantee fulfilled with
Voidbound to the providedGuaranteeDeclaration
Swift
public convenience init(_ guarantee: Guarantee<T>, context: CancelContext? = nil)Parameters
guaranteeGuaranteeto bindcontextoptional
CancelContextto associate with thisCancellableGuarantee -
Initializes a new promise fulfilled with
Voidand with the givenCancellableTaskDeclaration
Swift
public convenience init(task: CancellableTask)
View on GitHub
Install in Dash
CancellableGuarantee Class Reference