{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settle",
  "title": "Settle",
  "description": "Runs an action that may return a promise and reports whether it worked, and whether it had to wait. The Confirm button and the Inline edit share it.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/lib/settle.ts",
      "content": "/**\n * Runs `action` and calls `finish` with whether it worked, at once or when its\n * promise settles, and whether it had to wait for one: an action that answers\n * at once has nothing to show while it runs. A throw is a failure, and its\n * reason goes to `finish` too; a success passes on what the action gave back.\n * The Confirm button's action, the Inline edit's save, the Form's submit, the\n * Sign in block's requests and the Sign up block's resend share it.\n */\nexport function settle<Value>(\n  action: (() => Value | Promise<Value>) | undefined,\n  finish: (ok: boolean, waited: boolean, reason?: unknown, value?: Value) => void,\n) {\n  let result: Value | Promise<Value> | undefined\n  try {\n    result = action?.()\n  } catch (error) {\n    finish(false, false, error)\n    return\n  }\n  if (result instanceof Promise) {\n    result.then(\n      (value) => finish(true, true, undefined, value),\n      (error: unknown) => finish(false, true, error),\n    )\n  } else finish(true, false, undefined, result)\n}\n",
      "type": "registry:lib",
      "target": "@lib/settle.ts"
    }
  ],
  "type": "registry:lib"
}