Combine: Sharing Publishers
With this short reference code snippet, you will be able to share publishers and avoid multiple asynchronous downloads of the same data.
This brief overview will demonstrate some basic features that may come in handy when working with publishers in Combine, Apple's framework to handle asynchronous events by combining event-processing operators. The Publisher protocol declares a type that transmits a sequence of values over time that subscribers can receive as input by adopting the Subscriber protocol.
A typical use case for Combine would be handling asynchronous download of data from the internet using a URLSession dataTask. In a scenario like that, it can also be smart to share a publisher to avoid multiple downloads of the same data.
Become a free member or log in to proceed.