Skip to content

switch printer FSM to looplab/fsm#10

Merged
rusq merged 10 commits into
masterfrom
fsm
Jul 9, 2026
Merged

switch printer FSM to looplab/fsm#10
rusq merged 10 commits into
masterfrom
fsm

Conversation

@rusq

@rusq rusq commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

Refactors the LX-D02 print-job state machine to use github.com/looplab/fsm and adds job-scoped routing for FSM side effects. Internal print events now dispatch directly to the owning print job instead of sharing the notification queue, while printer notifications remain best-effort and non-blocking.

Why

The previous switch-based FSM mixed internal packet-stream completion with printer 5a06 completion and used shared channels that could deadlock or receive stale events. Follow-up review also found that required internal events could be dropped when the notification queue was full, and stale goroutines from a canceled print could affect the next print.

Changes

  • Add a per-print printJob owner for the FSM, notification queue, completion channel, cancellation, and packet-stream cancellation.
  • Split internal eventPacketsSent from printer eventNotificationFinished.
  • Dispatch required internal events directly through the owning job FSM so they cannot be dropped by a full notification queue.
  • Ignore stale job events after cancellation or replacement by a later print.
  • Return print failure/cancellation errors through single-shot completion handling.
  • Keep public printing APIs unchanged.
  • Update FSM tests to cover success, failures, cancellation, hold/retransmit, duplicate completion, full notification queues, stale init completion, stale packet stream events, and worker behavior with no active print.

Validation

  • go test ./...
  • go test -race ./...

@rusq
rusq marked this pull request as ready for review July 9, 2026 12:01
@rusq
rusq merged commit eb7414e into master Jul 9, 2026
1 check passed
@rusq
rusq deleted the fsm branch July 9, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant