Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用云功能更新文档时的事务延迟_Javascript_Firebase_Dart_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript 使用云功能更新文档时的事务延迟

Javascript 使用云功能更新文档时的事务延迟,javascript,firebase,dart,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Dart,Google Cloud Firestore,Google Cloud Functions,关于云功能,如果我更新事务中的某些文档, 更新是否在承诺结束后立即进行 我在应用程序中测试了这种行为:有时,当我对文档使用简单的get(没有持久性)时,在云函数(更新文档)结束后,文档不会立即更新 Typescript中的可调用云函数示例: exports.cloudFunctionExample = functions.https.onCall(async (data, context) => { await admin.firestore().runTransaction(a

关于云功能,如果我更新事务中的某些文档, 更新是否在承诺结束后立即进行

我在应用程序中测试了这种行为:有时,当我对文档使用简单的get(没有持久性)时,在云函数(更新文档)结束后,文档不会立即更新

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;
});
Dart应用程序示例:

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();

这是预期的行为吗?更新Firestore中的文档时,事务是否有延迟?

写入操作必须在写入承诺解决之前完成,但不一定是由这些写入操作触发的写入操作。您能否提供代码来演示在写入(设置或更新或事务中的数据)新数据的承诺完成后读取旧数据的过程?请编辑问题,以显示未按预期方式运行的完整、最少的代码,并解释它实际上在做什么@DougStevenson我已经用你要求的最少代码更新了这个问题。