7

So I have a Firebase Cloud Function that calls 2 async functions.

exports.someFunction = functions.firestore
  .document('some/path')
  .onCreate(event => {
    asyncFunction1();
    asyncFunction2();
  });

Both asyncFunction1 and asyncFunction2 return a promise.

Now, Firebase dictates that we should

Resolve functions that perform asynchronous processing (also known as "background functions") by returning a JavaScript promise.

However, since my function is performing two asynchronous processes, what should I return? I tried doing

exports.someFunction = functions.firestore
  .document('some/path')
  .onCreate(event => {
    return Promise.all(
      asyncFunction1(),
      asyncFunction2()
    );
  });

This works: both functions get called and executed correctly, but I also get the error TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined at Function.all when calling the Cloud Function.

Any ideas? Thanks in advance.

1 Answer 1

12

You can try Promise.all([asyncFunction1(), asyncFunction2()]). Look on link

2
  • 2
    He is passing arguments without square brackets. Mar 2, 2018 at 12:46
  • 1
    @MathiasLykkegaardLorenzen The devil is in the detail, :) Promise.all expects an array of promises, not a list of promises in the arguments.
    – Keith
    Mar 2, 2018 at 12:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.