Add async init for collections

sync3
Laurent 6 months ago
parent 7aaaadcf2b
commit 369c71ba4e
  1. 5
      LeStorage/BaseCollection.swift
  2. 7
      LeStorage/Store.swift

@ -65,6 +65,11 @@ public class BaseCollection<T: Storable>: SomeCollection, CollectionHolder {
/// Sets a max number of items inside the collection
fileprivate(set) var limit: Int? = nil
init(store: Store) async {
self.store = store
await self.loadFromFile()
}
init(store: Store, indexed: Bool = false, inMemory: Bool = false, limit: Int? = nil, synchronousLoading: Bool = false) {
if indexed {
self._indexes = [:]

@ -115,6 +115,13 @@ final public class Store {
return collection
}
func synchronizedCollectionWithFileLoading<T : SyncedStorable>() async -> SyncedCollection<T> {
let collection = await SyncedCollection<T>(store: self)
self._collections[T.resourceName()] = collection
self.storeCenter.loadApiCallCollection(type: T.self)
return collection
}
/// Registers a singleton object
/// - Parameters:
/// - synchronized: indicates if the data is synchronized with the server

Loading…
Cancel
Save