如果事务外部有更多的代码/逻辑,这些代码/逻辑只应在事务成功时运行,这些代码是否会在重试成功后运行?请参阅下面基于我的Express路由处理程序的解释示例。
app.post('/some/path/to/endpoint', async (req, res) => {
try {
await db.runTransaction(async t => {
const snapshot = t.get(someDocRef);
const data = snapshot.data();
doSomething(snapshot);
return t.update(snapshot.ref, { someChanges });
});
// QUESTION: If transaction retries and succeeds, will the below code run once?
// logic that requires the transaction succeeds
await axios.post(url, data);
res.status(200).send('success');
} catch (e) {
res.status(500).send('system error');
}
});
感谢专家对此的看法。谢谢
发布于 2021-11-09 08:06:02
您可以找到runTransaction here的文档。
如您所见,runTransaction()
返回一个Promise。当您等待一个Promise,并且您的代码被插入try/catch块时,如果抛出一个错误,之后的所有内容都将被忽略,因为流将进入catch语句。
所以答案是肯定的:如果出了问题,runTransaction()之后的所有东西都不会被执行。
https://stackoverflow.com/questions/69894516
复制相似问题