The preceding demo retried a courier once. Here the score service is a local deterministic fake API: createScoreApi(failures) returns a function that rejects a chosen number of times before accepting a score. It never sends a request.
A separate retry loop stops once a local operation succeeds:
async function repeatUntilReady(action, limit) {
for (let attempt = 1; attempt <= limit; attempt++) {
try { return await action(); }
catch (error) { if (attempt === limit) throw error; }
}
}
// An action that rejects once then succeeds would be called twice.
deliverScore(api, score, maxAttempts) to return api(score)’s result on success. Assume a whole-number attempt budget.maxAttempts calls.Error("No attempts allowed") without calling the API.reportDelivery() with createScoreApi(2), score 87, and three attempts. Log Score 87 saved after 3 attempts. The starter calls it.You can coordinate dependent requests, preserve partial results, and stop retries safely. The quiz checks these decisions.