Summary
Expose a “wait until settled” promise on Send and Melt flows so callers can await terminal completion without wiring event listeners or polling.
Problem
SendApi.executePreparedSend() (packages/core/api/SendApi.ts) returns a pending operation + token, but callers must manually watch events or call checkPendingOperation() to know when it finalizes or rolls back.
QuotesApi.executeMelt() may return a pending operation; callers must poll checkPendingMelt() or listen for melt-op:* events to know when it settles.
- This is especially painful for CLI/short-lived apps that want to “do the thing then exit”.
Proposal
Return an additional promise from the public APIs that resolves when the flow reaches a terminal state.
Suggested API shape (additive)
- Send
SendApi.executePreparedSend() → { operation, token, settled }
- Melt
QuotesApi.executeMelt() / executeMeltByQuote() → { operation, settled }
settled resolves with the terminal operation, and rejects on explicit failure or timeout.
Settlement definition
- Send:
send:finalized or send:rolled-back
- Melt:
melt-op:finalized or melt-op:rolled-back (and failed if exposed)
Implementation notes
- Build a small helper that:
- Checks current state first (fast-path if already terminal).
- Subscribes to
EventBus events (CoreEvents) and auto-unsubscribes on resolve/reject.
- Optionally accepts timeout (default off or reasonable).
- Ensure listeners are cleaned up to avoid leaks.
- Document that settlement depends on watchers/processors being enabled (or add an internal polling fallback if desired).
Acceptance criteria
- Send and Melt flows expose a
settled promise without breaking existing return types.
settled resolves on terminal state transitions and unsubscribes listeners.
- Immediate resolution if the operation is already terminal.
- Tests cover:
- immediate terminal resolve
- pending → terminal resolve
- rollback/failure handling
- unsubscribe cleanup
Notes
- Mint flow should be tackled once MintSaga is implemented.
Summary
Expose a “wait until settled” promise on Send and Melt flows so callers can await terminal completion without wiring event listeners or polling.
Problem
SendApi.executePreparedSend()(packages/core/api/SendApi.ts) returns a pending operation + token, but callers must manually watch events or callcheckPendingOperation()to know when it finalizes or rolls back.QuotesApi.executeMelt()may return a pending operation; callers must pollcheckPendingMelt()or listen formelt-op:*events to know when it settles.Proposal
Return an additional promise from the public APIs that resolves when the flow reaches a terminal state.
Suggested API shape (additive)
SendApi.executePreparedSend()→{ operation, token, settled }QuotesApi.executeMelt()/executeMeltByQuote()→{ operation, settled }settledresolves with the terminal operation, and rejects on explicit failure or timeout.Settlement definition
send:finalizedorsend:rolled-backmelt-op:finalizedormelt-op:rolled-back(andfailedif exposed)Implementation notes
EventBusevents (CoreEvents) and auto-unsubscribes on resolve/reject.Acceptance criteria
settledpromise without breaking existing return types.settledresolves on terminal state transitions and unsubscribes listeners.Notes