From 59391c74d94818753007433bec3ef4b3170626b9 Mon Sep 17 00:00:00 2001 From: hypercross Date: Sat, 25 Apr 2026 15:57:59 +0800 Subject: [PATCH] refactor(samples): use produceAsync in tic-tac-toe Update the tic-tac-toe sample to use `produceAsync` instead of `produce` to ensure state mutations correctly await interruption promises. --- src/samples/tic-tac-toe.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/samples/tic-tac-toe.ts b/src/samples/tic-tac-toe.ts index 72e91b2..ffa94d6 100644 --- a/src/samples/tic-tac-toe.ts +++ b/src/samples/tic-tac-toe.ts @@ -77,7 +77,7 @@ export async function start(game: TicTacToeGame) { const turnNumber = game.value.turn + 1; const turnOutput = await turn(game, currentPlayer, turnNumber); - game.produce((state) => { + await game.produceAsync((state) => { state.winner = turnOutput.winner; if (!state.winner) { state.currentPlayer = state.currentPlayer === "X" ? "O" : "X"; @@ -111,7 +111,7 @@ async function turn( game.value.currentPlayer, ); - placePiece(game, row, col, turnPlayer); + await placePiece(game, row, col, turnPlayer); const winner = checkWinner(game); if (winner) return { winner }; @@ -163,7 +163,7 @@ export function checkWinner(host: TicTacToeGame): WinnerType { return null; } -export function placePiece( +export async function placePiece( host: TicTacToeGame, row: number, col: number, @@ -177,7 +177,7 @@ export function placePiece( player, id: `piece-${player}-${moveNumber}`, }; - host.produce((state) => { + await host.produceAsync((state) => { state.parts[piece.id] = piece; board.childIds.push(piece.id); board.partMap[`${row},${col}`] = piece.id;