Classes
The following classes are available globally.
-
Cache
This class functions as a shared container of queries which can be live-updated from subscriptions. For example, you might combine
HARequestType.getStates
withHAEventType.stateChanged
to get all states and be alerted for changes.All methods on this class are thread-safe.
Important
You, or another object, must keep a strong reference to this cache or a HACancellable returned to you; the cache does not retain itself directly. This includes
map
values.Note
Use
shouldResetWithoutSubscribers
to control whether the subscription is disconnected when not in use.Note
Use
map(_:)
to make quasi-streamed changes to the cache contents.Declaration
Swift
public class HACache<ValueType>
-
Container for caches
You can create your own cache accessible in this container like so:
Create a key to represent your cache:
struct YourValueTypeKey: HACacheKey { func create(connection: HAConnection) -> HACache<YourValueType> { return HACache(connection: connection, populate: …, subscribe: …) } }
Add a convenience getter to the container itself:
extension HACachesContainer { var yourValueType: HACache<YourValueType> { self[YourValueTypeKey.self] } }
Then, access it from a connection like
See moreconnection.caches.yourValueType
.Declaration
Swift
public class HACachesContainer
-
Wrapper around a value with a lock
Provided publicly as a convenience in case the library uses it anywhere.
See moreDeclaration
Swift
public class HAProtected<ValueType>