Skip to content

Commit 3d3e049

Browse files
committed
Add NSPersistentContainer.loadPersistentStores()
1 parent 6a922cb commit 3d3e049

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Sources/CoreDataModel/NSPersistentContainer.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,24 @@ extension NSPersistentContainer: ModelStorage {
4444
}
4545
}
4646
}
47+
48+
internal extension NSPersistentContainer {
49+
50+
func loadPersistentStores() -> AsyncThrowingStream<NSPersistentStoreDescription, Error> {
51+
assert(self.persistentStoreDescriptions.isEmpty == false)
52+
return AsyncThrowingStream<NSPersistentStoreDescription, Error>.init(NSPersistentStoreDescription.self, bufferingPolicy: .unbounded, { continuation in
53+
self.loadPersistentStores { [unowned self] (description, error) in
54+
continuation.yield(description)
55+
if let error = error {
56+
continuation.finish(throwing: error)
57+
return
58+
}
59+
if description == self.persistentStoreDescriptions.last {
60+
continuation.finish()
61+
}
62+
}
63+
})
64+
}
65+
}
66+
4767
#endif

0 commit comments

Comments
 (0)