I come from a language with no promises :-(
I want to code some NodeJS utility functions like these to interface with FireBase. It is my understanding that all FB functions return a promise (but, feel free to correct me).
exports.writeToFireBase(url, value){
try{
promise = await admin.database().ref(url).set(value);
return promise;
}
catch(exception){
exports.unhandledException(exception);
}
}
exports.readFromFireBase(url){
try{
let value = admin.database().ref(url).once("value");
return value;
}
catch(exception){
exports.unhandledException(exception);
}
}
What are functions actually returning?
In the write case, I guess it is either a promise, or nothing?
In the read case, will my function return the actual data, or a promise to that data? Await looks to me like it is blocking, but I suspect that I am wrong, and that promise to the data is returned from my read function.
Can someone please clarify, before I base too much code on erroneous assumptions?