Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous https firebase functions

Should HTTPS functions return asynchronous promises like realtime functions have to? We haven't been returning in HTTPS functions (just using res.status.send etc), and it looks like firebase/function-samples aren't either. But the documentation is slightly ambiguous https://firebase.google.com/docs/functions/terminate-functions .

like image 581
Alan Avatar asked Nov 29 '22 22:11

Alan


2 Answers

This works now in the latest Firebase:

exports.asyncFunction = functions.https.onRequest(async (request, response) => {
    const result = await someAsyncFunction();
    response.send(result);
});
like image 195
Dávid Veszelovszki Avatar answered Dec 04 '22 13:12

Dávid Veszelovszki


HTTP functions currently do not respect returned promises - they require a sent result in order to terminate normally. If an HTTP function doesn't send a result, it will time out.

All other types of functions require a returned promise in order to wait for asynchronous work to fully complete.

If you don't have any async work to wait for, you can just return immediately.

These are the three cases outlined in the docs.

like image 37
Doug Stevenson Avatar answered Dec 04 '22 12:12

Doug Stevenson