fsl.tools
// Real world r12

Fetch with retry

A request that can succeed, fail, or be retried — without a tangle of nested if-statements. The graph names every legal transition; the calling code stays flat.

Code

request.fsl
const req = sm`
  idle     'fetch'    loading;
  loading  'resolve'  success;
  loading  'reject'   error;
  error    'retry'    loading;
  success  'reset'    idle;
`;
run.ts
async function run() {
  req.go('fetch');
  try { const data = await api.get(); req.go('resolve', { data }); }
  catch { req.go('reject'); }
}

Graph

fetch resolve reject retry reset idle loading success error