I have a Cloud Function that does some searching on my database. It's quite an expensive process that involves a lot of computing. Its goal is to find the best possible match. I have no way doing an early exit when a good match is found because a better one might be found later in the iteration cycle. So ideally I want to update the client regularly about the best matches so far. The issue is for a HTTP Cloud Function I can only return once. I was thinking of updating the results on the database somewhere and have the client listen in for changes, however, this may not be much faster since there will be some delay in that process too. So is there a way of returning multiples responses to a HTTP query in a Cloud Function? Is there a better solution to this I am not seeing?
Pseudo of what I need
def cloudFunction(someData):
goodMatches = []
for i in database:
if (i == goodMatch):
goodMatches.append(goodMatch)
post new goodMatch to client
return goodMatches
An HTTP type function can only have one response, and it will be sent in its entirety. Cloud Functions does not support HTTP chunking or streaming of results. If you want to send progressive results, consider writing those into Cloud Firestore or Realtime Database at a unique location that's agreed upon between the client and the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With