Which fix removes the race?
let seq = 0;
async function next() {
const v = seq;
await tick();
seq = v + 1;
return seq;
}
- Increment before awaiting:
seq += 1first - Increment before awaiting:
seq == 1first - Wrap the body in a
try/finallyblock - Change
let seqtoconst seqat the top
Two concurrent calls both read the old value across the await and write the same number.
Play Problem Solving ▸