Turn-based matches
Asynchronous multiplayer (chess, words, card games) over HTTP — no realtime connection needed.
For turn-based games, players don't need to be online at the same time. A match holds shared state and a turn order; each player submits their turn when it's their move. No WebSocket or Durable Object required.
const { match } = await tg.asyncMatch.create({ type: 'chess', opponents: ['p_9'] });
const mine = await tg.asyncMatch.mine(); Server-enforced turns + OCC
The server enforces turn order (not_your_turn out of turn) and optimistic concurrency (async_conflict on a stale version) — so two devices can't both move. Read the match, submit with the version you saw.
await tg.asyncMatch.turn(match.id, { state: nextState, version: match.version, end: false });
await tg.asyncMatch.forfeit(match.id);