Close database connection after callback call
1 answer
Yes, he will always be called, assuming that callback(err)
he does not, he throws himself.
This code is almost equivalent (slightly different from error handling) and a little more concise:
doStuff()
.then(callback, callback)
.then(db.close)
Another point worth mentioning is that if it db
is an instance of a class and close()
relies on it with a keyword this
, then passing it in this way can be problematic as it loses that context when on its own.
+2
source to share