0

According to https://cloud.google.com/functions/docs/writing/background

You use background functions when you want to have your Cloud Function invoked indirectly in response to an event, such as a message on a Cloud Pub/Sub topic, a change in a Cloud Storage bucket, or a Firebase event.

And the function paramaters are (data, context, callback): https://cloud.google.com/functions/docs/writing/background#function_parameters

However, when I write a simple function like

exports = module.exports = functions.firestore
.document(path)
.onWrite((change, context, callback) => {

   callback()
   return
})

I get an error that says

TypeError: callback is not a function

Is callback not part of Firestore background functions? The documentation says it is

If not, is there anyway to immediately exit a function?

1 Answer 1

1

The Firebase API is different than the Google Cloud API. What you linked to was the Cloud API, which accepts a callback parameter. The Firebase API which you are actually using does not. The Firebase API for background functions requires you to return a promise that resolves after all the work is complete. There is no callback to call in that case.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. What type of event is it referring to when it says "or a Firebase event"?
An event represents something that happened in a Firebase or Google Cloud product.
Okay so for everyone looking at this, don't use the Firebase example they give on the Firebase page, callbacks don't work. Use return null instead of callback(): firebase.google.com/docs/functions/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.