Classes
The following classes are available globally.
-
AsyncLoadable is a concrete implementation of
See moreAsyncLoadableProtocol, subclass from this class to make your own loadable, so you can avoid working with generics “down the line”. -
See moreMMMLoadableObserverthat supports asynchronous closures as it’s callback. -
Listen to an
AsyncLoadableby using anAsyncStream. This allows you to iterate over theiterator, this will stream a newAsyncLoadableStreamObjecton every change in the loadable.For example:
class MyView: UIView { private let loadable: AsyncLoadable<MyData> // It's crucial that we call `finish()` somehow, this is also called upon deinit, // so storing it as a property is an easy way to accomplish this. private var stream: AsyncLoadableStream<MyData>? public init(loadable: AsyncLoadable<MyData>) { let stream = AsyncLoadableStream(loadable) self.loadable = loadable self.stream = stream for await obj in stream.iterator { // Do something with the stream object, e.g. update UI. updateUI() } } private func updateUI() { loader.isHidden = loadable.loadableState != .syncing } }Please note that due to the nature of
See moreasync/awaitin swift it’s crucial to store the stream as a local (private) property to ensure thatfinish()get’s called upondeinit. This stops the stream. Otherwise yourActorwill get blocked indefinitely, since it will keep on waiting for new values, causing a memory leak.
View on GitHub
Classes Reference