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 CancellableGuaranteeDeclaration
Swift
public var guarantee: Guarantee<T>
-
Type of the delegate
thenable
Declaration
Swift
public typealias U = Guarantee<T>
-
Delegate
thenable
for 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
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.
-
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
Void
Declaration
Swift
public convenience init(context: CancelContext? = nil)
Parameters
context
optional
CancelContext
to associate with thisCancellableGuarantee
-
Initializes a new cancellable guarantee fulfilled with
Void
bound to the providedGuarantee
Declaration
Swift
public convenience init(_ guarantee: Guarantee<T>, context: CancelContext? = nil)
Parameters
guarantee
Guarantee
to bindcontext
optional
CancelContext
to associate with thisCancellableGuarantee
-
Initializes a new promise fulfilled with
Void
and with the givenCancellableTask
Declaration
Swift
public convenience init(task: CancellableTask)