Firebase REST端点。我在启动时获得了很多NULL返回。通过其他问题,我认为这是一个Coldstart。我相信问题是我使用的回调在firebase有机会返回数据集之前返回。我从@puf - frank-van-puffelen那里读到了关于callabcks的评论 消化冷启动。所以我试图重写作为承诺。这段代码通常可以工作,但仍然可以获得冷启动NULL数据集。我怎么做这个承诺?
var functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
//=================================================================================================
// KeysFromAccountGet01
//=================================================================================================
// This function is not working correctly because it often returns a NULL set. probably
// because I am using callbacks instead of promises, and the callback returns before firebase
// can return a query. Usually it works.
// But I am fairly sure that I should be using PROMICES so as to wait for the data to arrive.
// that said, I can not figure out how to do a promise. Everythign I have tried returns nothing.
// some sugestions on how to do promises for this would be appreciated.
//curl 'https://us-central1-test.cloudfunctions.net/KeysFromAccountGet01?account=dporras8'
//curl 'https://us-central1-test.cloudfunctions.net/KeysFromAccountGet01?account='
//firebase deploy --only functions:KeysFromAccountGet01
exports.KeysFromAccountGet01 = functions.https.onRequest((req, res) =>{
var arr =[];
arr.push("1====+++starting");
arr.push("acount = "+ req.query.account);
admin.database().ref('/newacctok/'+req.query.account+'/tok3/').on('value', function(snapshot){
snapshot.forEach(function(miniSnapShot){
var tt = miniSnapShot.val();
var json = ({
"key":miniSnapShot.key,
"account":req.query.account,
"uuid":tt.uuid,
"ts2":tt.ts2,
"token":tt.token
});
arr.push(json);
})
.then(res.status(200).send(arr));
});
//===================================
答案 0 :(得分:1)
我不确定这些更改是否会对您的Null返回有所帮助。请注意,我将on()
更改为once()
,而exports.KeysFromAccountGet01 = functions.https.onRequest((req, res) => {
var arr =[];
arr.push("1====+++starting");
arr.push("acount = "+ req.query.account);
// note change from on() to once()
admin.database().ref('/newacctok/'+req.query.account+'/tok3/').once('value')
.then(snapshot => {
snapshot.forEach(miniSnapShot => {
var tt = miniSnapShot.val();
var json = ({
"key":miniSnapShot.key,
"account":req.query.account,
"uuid":tt.uuid,
"ts2":tt.ts2,
"token":tt.token
});
arr.push(json);
});
res.status(200).send(arr)
});
});
将附加了侦听器。此外,我还看到了Frank van Puffelen的回答,提醒他们不要在HTTPS请求函数中执行异步处理。我会尝试找到他的答案/评论并添加它们。
int a=5;
int *p;
p=&a;
char *a0;
a0=(char* )p;