Transaction delay when update documents using cloud function

Viewed 271

About cloud functions, if I update some document within a transaction, does the update occur immediately after the promise conclusion?

I was testing this behaviour in my application: Sometimes, when I use a simple get (without persistence) on the document, after the cloud function (that updates the document) concludes, the document does not update immediately.

Example of a callable cloud function in Typescript:

exports.cloudFunctionExample = functions.https.onCall(async (data, context) => {

    await admin.firestore().runTransaction(async (transaction: Transaction) => {

        const docExample: DocumentSnapshot = await transaction.get('colllectionExample/docExample');

        await transaction.update(docExample.ref, {"newKey": "newValue"})
   });

   return null;
});

Example of a Dart application:

HttpsCallable functionCallable = CloudFunctions().getHttpsCallable(
  functionName: 'cloudFunctionExample',
);

await functionCallable.call();

DocumentSnapshot docExample = await Firestore().document('colllectionExample/docExample').get(source: Source.server);

if (docExample.data["newKey"] != "newValue") 
  throw AssertionError();

Is this the expected behaviour? Do transactions have some delay when updating documents in Firestore?

0 Answers
Related