Migrating from PromiseKit¶
Similarities¶
Below are some PromiseKit operations and their equivalents in Async+:
firstly
->attempt
then
->then
(but it doesn't always need to return a value)map
->then
with a non-async body returning a valuecompactMap
-> usethen
returning 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
->recover
get
->then
that doesn't return anythingtap
->tap
(not implemented yet)ensure
->ensure
done
->then
without returning a valuecatch
->catch
finally
->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.