order

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package order is a payment-order state machine: submit a charge to a provider, resend on timeout up to MaxRetries, and finish as Paid, Failed or Cancelled.

Index

Constants

View Source
const MaxRetries = 3

MaxRetries is the protocol's resend budget before giving up.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actions

type Actions uint64

Actions is the set of things the holder must do after a transition, one bit each. The holder performs them in declaration order. The zero value is the empty set.

const (
	ActSend Actions = 1 << iota
	ActResend
	ActStartTimer
	ActCancelTimer
	ActModeChanged
)

Actions values.

type Event

type Event uint8

Event is an input to Fire.

const (
	EvSubmit Event
	EvAck
	EvTimeout
	EvCancel
)

Event values.

func (Event) String

func (e Event) String() string

type Machine

type Machine struct {
	// contains filtered or unexported fields
}

Machine is one order. Build it with New and change it only with Fire.

func New

func New() Machine

New returns an order in Idle.

func (Machine) Fire

func (m Machine) Fire(e Event) (Machine, Actions, fsm.Outcome)

Fire applies e and returns the next machine, the actions to perform and what happened.

func (Machine) Mode

func (m Machine) Mode() Mode

Mode derives the mode from the state.

func (Machine) Retries

func (m Machine) Retries() int64

Retries returns how many resends have been made.

func (Machine) State

func (m Machine) State() State

State returns the control state.

type Mode

type Mode uint8

Mode is derived from State.

const (
	Normal Mode
	Closed
)

Mode values.

func (Mode) String

func (m Mode) String() string

type State

type State uint8

State is an order's control state.

const (
	Idle State
	Pending
	Failed
	Cancelled
)

State values.

func (State) String

func (s State) String() string

Directories

Path Synopsis
cmd
orderd command
Command orderd drives one order from commands on standard input ("submit", "ack", "cancel"), with a real timer for timeouts.
Command orderd drives one order from commands on standard input ("submit", "ack", "cancel"), with a real timer for timeouts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL