Streamlined Future
This release is all about performance and quality of life improvements.
flatMap
. Add variants which allow combinations of Future<T, E>.flatMap { Future<T, Never> }
and Future<T, Never>.flatMap { Future<T, E> }
on(scheduler:success:failure:completion:)
method to change a scheduler you now call a separate observe(on scheduler:)
or observe(on queue:)
(new!) method before attaching callbacks. The observe(on:)
methods are almost instanteneous thanks to the fact that Future
is a struct
now.Promise<Int, Error>()
instead of Future<Int, Error>.promise
Future(value: 1)
now compiles and automatically infers type to be Future<Int, Never>
attemptMap
to tryMap
, implement tryMap
in terms of flatMap
ignoreError
, materialize
is a better alternativeon
would result in these callbacks called on the same run of run loop on the selected queue/schedulerFuture.init(result:)
, Promise.resolve(result:)
CancellationTokenSource
using Future
, simpler implementationFuture
is a struct now. Future(value:)
and Future(error:)
are now 2.5x times fasterobserve
directly)Scheduler
enum, it's a simple function now. See Threading for more info.FutureX is a completely new beast. It has a new name and it a new goal - to provide the best future implementation in Swift.
There are a lot of improvements in the core part of the frameworks:
Scheduler
instead of DispatchQueue
. By default the callbacks are now run with .main(immediate: true)
strategy. It runs immediately if on the main thread, otherwise asynchronously on the main thread. The rationale is provided in README.on
now returns self so that you can continue the chain. The returned result is marked as discardable.Promise
is now nested in Future<Value, Error>
like other types like Result
. To create a promise call Future<Value, Error>.promise
.zip
, reduce
to extension Future where Value == Any, Error == Any
so that Future
would be a simple namespace (inspired by RxSwift)isPending
Future<Value, Error>.Result
Equatable
There are also lots of bonus additions:
first
after
: Returns a future which succeeds after a given time interval.retry
castError
ignoreError
materialize
that uses built-in Never
to indicate that the error is not possiblecastError
mapThrowing
FutureX now ships with a CancellationToken
implementation. See rational in README.
An initial version of Future extensions for native frameworks.
wait
method that blocks the current thread and waits until the future receives a resultFuture.Result
type publicmap
and mapError
now no longer require intermediate Future
instance to be created, increased performance by up to 40%.map
, flatMap
, mapError
, flatMapError
now run on the queue on which the future was resolved. It increases the performance of a typical chain by up to 3 times and also simplifies debugging - there are less queue.async
operations being performed.observeOn
. It was introducing unwanted state in Future
. To observe success/failure on a different queue use a new queue
parameter (DispatchQueue.main
by default) of on
method.zip
with three futures as argumentsPill 0.6 is a complete reimagining of the library. See a post for an overview of the changes.
Future<Value, Error>
, Promise<Value, Error>
map
, flatMap
instead of then
zip
, reduce
observeOn
method to observe changes on differnet dispatch queuesthrows
support (not type-safe)