Skip to content

Add settled promise for send/melt flows #82

@Egge21M

Description

@Egge21M

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    To Do

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions