Skip to content

Commit

Permalink
Expose Firestore.terminate (#51)
Browse files Browse the repository at this point in the history
Also fixes signature of `clearPermanence` to allow for a nil completion
callback to match the Obj C API.
  • Loading branch information
darinf authored Mar 18, 2024
1 parent bb46041 commit c14c6f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Sources/FirebaseFirestore/Firestore+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ public class Firestore {
}
}

public func clearPersistence(completion: @escaping () -> Void) {
public func clearPersistence(completion: (() -> Void)?) {
let future = swift_firebase.swift_cxx_shims.firebase.firestore.firestore_clear_persistence(impl)
future.setCompletion({
DispatchQueue.main.async {
completion()
if let completion {
DispatchQueue.main.async {
completion()
}
}
})
}
Expand All @@ -62,6 +64,26 @@ public class Firestore {
}
}

public func terminate(completion: (() -> Void)?) {
let future = swift_firebase.swift_cxx_shims.firebase.firestore.firestore_terminate(impl)
future.setCompletion({
if let completion {
DispatchQueue.main.async {
completion()
}
}
})
}

public func terminate() async {
await withCheckedContinuation { continuation in
let future = swift_firebase.swift_cxx_shims.firebase.firestore.firestore_terminate(impl)
future.setCompletion({
continuation.resume()
})
}
}

public func document(_ documentPath: String) -> DocumentReference {
swift_firebase.swift_cxx_shims.firebase.firestore.firestore_document(impl, std.string(documentPath))
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/firebase/include/FirebaseFirestore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ firestore_clear_persistence(::firebase::firestore::Firestore *firestore) {
return VoidFuture::From(firestore->ClearPersistence());
}

inline VoidFuture
firestore_terminate(::firebase::firestore::Firestore *firestore) {
return VoidFuture::From(firestore->Terminate());
}

inline ::firebase::firestore::DocumentReference
firestore_document(::firebase::firestore::Firestore *firestore,
const ::std::string &document_path) {
Expand Down

0 comments on commit c14c6f4

Please sign in to comment.