I have a low level common function which is the bottom of the call tree in many places.
There is an async transaction, and I want to block until the async request completes, before returning.
I could use await
. E.g await admin.database().ref(url).update(value);
.
But, if I use await
then I must mark the function as async
. Which means that must mark all of its callers as async
, and all of theirs, all the way up to the top.
Would it be evil of me to code my blocking function like this?
Perhaps I am missing something?
/**
* Perform a blocking write to the database. It is the responsibility of the caller to catch any exceptions.
*
* @param {string} url - the URL of the node to be updated.
* @param {string | Object} value - the value to be written
*/
expors.updateDatabase = function(url, value){
admin.database().ref(url).update(value).then(() => {
return;
});
}
This might sound opinion-based, and I won't deny that I would be happy to hear about industry standard best practise, but what I am really after is whether there is any technical reason not to do this.