How do I clean up resources after doing a Firestore operation, I want to use the "finally" block to close a dialog after saving the record but it complains it is not a function. I been searching for the API reference but all I find is the few examples in the getting started section.
my code is something like this:
db.collection("posts")
.doc(doc.id)
.set(post)
.then(function(docRef) {
//todo
})
.catch(function(error) {
console.error("Error saving post : ", error);
})
/*.finally(function(){
//close pop up
})*/
;
Native Promises in node 6 don't have a finally() method. There is just then() and catch(). (See this table, node is on the far right.)
If you want do do something unconditionally at the end of a promise chain regardless of success or failure, you can duplicate that in both then() and catch() callbacks:
doSomeWork()
.then(result => {
cleanup()
})
.catch(error => {
cleanup()
})
function cleanup() {}
Or you can use TypeScript, which has try/catch/finally defined in the language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With