Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Typescript 可以在事务中使用带有更新的异步编程吗?_Typescript_Google Cloud Firestore_Async Await - Fatal编程技术网

Typescript 可以在事务中使用带有更新的异步编程吗?

Typescript 可以在事务中使用带有更新的异步编程吗?,typescript,google-cloud-firestore,async-await,Typescript,Google Cloud Firestore,Async Await,在VSCode中,当我在事务更新之前添加wait关键字时,单词wait会加下划线,当我在上面滚动时,会看到消息“wait对该表达式的类型没有影响。ts(80007)” 这个消息正确吗?如果是这样,事务中的更新是否会导致任何同步性问题 我实际上并没有在我的应用程序中使用TypeScript,但我想这条消息仍然可能是相关的 如果有帮助,下面是事务的完整代码。这是一款扑克应用程序,其目标是确保当多个玩家同时加入一张桌子时,不会试图添加超过允许数量的玩家 playersNumberAfterTransa

在VSCode中,当我在事务更新之前添加wait关键字时,单词wait会加下划线,当我在上面滚动时,会看到消息“wait对该表达式的类型没有影响。ts(80007)”

这个消息正确吗?如果是这样,事务中的更新是否会导致任何同步性问题

我实际上并没有在我的应用程序中使用TypeScript,但我想这条消息仍然可能是相关的

如果有帮助,下面是事务的完整代码。这是一款扑克应用程序,其目标是确保当多个玩家同时加入一张桌子时,不会试图添加超过允许数量的玩家

playersNumberAfterTransaction = await firestore.runTransaction( async(t) => {
    const firstNotFullTableDocSnapshot = await t.get(firstNotFullTable.ref);
    const firstNotFullTableDocRef = firstNotFullTableDocSnapshot.ref;
    const newPlayersNumber = firstNotFullTableDocSnapshot.data().playersNumber + 1;
    if (newPlayersNumber < 9) {
      const seat = firstNotFullTableData.seatsRemaining.pop();
      player.seat = seat;
      if (!cardsData) {
        cards = await generateDeckOfCards();
        await firstNotFullTable.ref.collection('cards').doc('deck').set({
          gameCards: cards,
        })
      }
      await t.update(firstNotFullTableDocRef, {playersNumber: newPlayersNumber, seatsRemaining: firstNotFullTableData.seatsRemaining})
      await newPlayerDocRef.set(
          player
      )
      return newPlayersNumber;
    } else {
      throw 'too many players at table'
    }
  })
playerNumberFrafterTransaction=等待firestore.runTransaction(异步(t)=>{
const firstNotFullTableDocSnapshot=等待t.get(firstNotFullTable.ref);
const firstNotFullTableDocRef=firstNotFullTableDocSnapshot.ref;
const newPlayersNumber=firstNotFullTableDocSnapshot.data().playersNumber+1;
如果(新玩家编号<9){
const seat=firstNotFullTableData.seatslaining.pop();
player.seat=座位;
如果(!cardsData){
卡片=等待生成卡片();
等待firstNotFullTable.ref.集合('cards').doc('deck').set({
游戏卡:卡片,
})
}
等待t.update(firstNotFullTableDocRef,{PlayerNumber:NewPlayerNumber,座位剩余:firstNotFullTableData.Seats剩余})
等待newPlayerDocRef.set(
运动员
)
返回newPlayersNumber;
}否则{
“桌上球员太多”
}
})

在事务内部,不要返回承诺。它们是同步的,并返回当前事务对象。TypeScript提醒你这一点。当事务处理程序返回时,写入将排队并作为批处理执行,因此无需等待任何操作。

请编辑问题以显示此处引用的完整代码。你现在拥有的东西被切断了。将文本复制到问题本身总比截图好。我做了这些更改。