Swiftpack.co - Package - koher/future-keep

FutureKeep

FutureKeep makes it possible to keep subscriptions of Futures or other Publishers in Combine until they are completed. It is useful to replace completion handlers with Futures when cancellations are not required.

// Keeps a reference to the subscription
// until it is complete.
future.get { value in
    // Uses `value` here
}

get can be used instead of sink. When we use sink, subscriptions are cancelled unless references to cancellables are kept.

// Subscriptions are cancelled
// just after the `sink` is called.
_ = future.sink { value in
    // Uses `value` here
}

When the Failure type of a Publisher is Never, closures receive an Output as its argument. Otherwise, closures receive a Result<Output, Failure>.

Notice: Using get of uncompletable Publishers causes memory leaks. Use get for only completable Publishers.

License

MIT

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

Make `get` available for any `Publisher`s - 2020-08-25 03:20:26

This makes it available to use get in various cases. For example, get is available now even after a Future is mapped.

future.map { ... }.get { ... }

0.1.0-beta - 2020-07-11 05:37:57