Migrating from PromiseKit¶
Similarities¶
Below are some PromiseKit operations and their equivalents in Async+:
firstly->attemptthen->then(but it doesn't always need to return a value)map->thenwith a non-async body returning a valuecompactMap-> usethenreturning a value, combined with a helper extension for optional calledunwrapOrThrow. Use this on the optional value when you return to replicate the behavior ofcompactMap.recover->recoverget->thenthat doesn't return anythingtap->tap(not implemented yet)ensure->ensuredone->thenwithout returning a valuecatch->catchfinally->finally
Differences¶
Additionally, these operations offer functionality that is different from PromiseKit:
.catch()with throwing body: this essentially just maps errors to one another while preventing further calls tothen..throws(): If the chain is able to be evaluated instantaneously, then this returns the value or throws..async(): Can use on a guarantee (which is returned by a non-throwingrecover)..asyncOptional(): For failable async chains: Async call that returns an optional value of the result..asyncResult(): Async call that returns aSwift.Result<T, Error>(the Async+ framework defines its own result type)..asyncThrows(): Async call that returns the value or throws.