Skip to content

feat: add opt-in progress callback to GetFlashMD5 - #51

Merged
deadprogram merged 1 commit into
tinygo-org:mainfrom
jgangemi:jae/md5-progress
Jul 11, 2026
Merged

feat: add opt-in progress callback to GetFlashMD5#51
deadprogram merged 1 commit into
tinygo-org:mainfrom
jgangemi:jae/md5-progress

Conversation

@jgangemi

@jgangemi jgangemi commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in ProgressFunc to GetFlashMD5, completing progress-callback coverage for the long-running flash operations (flash, erase, and read already report progress).

Like whole-chip erase, an on-device MD5 is a single blocking command — the device stays silent until the digest is ready, so there is no per-chunk protocol seam for byte-accurate progress. This reports a synthetic ETA (elapsed / estimated-total milliseconds) ticked against the size-scaled MD5 timeout, matching the ProgressFunc convention already used by EraseFlash/EraseRegion.

Behavior

  • progress == nil → unchanged; no goroutine is spawned (opt-in cost only).
  • non-nil → a ticker (500ms, monotonic, capped at estimate−1) runs while the blocking MD5 command executes; it is always stopped and joined before returning (no goroutine leak), never touches the connection, and emits a final (est, est) only on success.
  • Intermediate ticks are best-effort: a panicking callback on an intermediate tick is recovered and dropped rather than crashing the process (the tick runs off the caller's goroutine); the final synchronous tick propagates, consistent with the other ProgressFunc call sites.

Tests

  • nil path leaves the goroutine count unchanged; non-nil path fires at least one intermediate tick plus a final (est, est), monotonic and capped; the error path omits the final tick; the ticker joins on success, error, and panic; and an intermediate-callback panic is dropped without crashing.

- add trailing ProgressFunc param to GetFlashMD5
- nil preserves today's exact behavior, no goroutine spun up
- non-nil ticks a synthetic ETA (elapsed/estimated ms) every 500ms against
  the existing size-scaled md5TimeoutForSize timeout, since the device stays
  silent for the duration of the hash computation
- extract md5TimeoutForSize in protocol.go from flashMD5's inline calc so
  both the real command timeout and the ticker estimate share one formula
- extract tickMD5 helper with an injectable interval for fast unit tests
- final progress call only fires on success; ticker goroutine is always
  joined before returning and never touches the connection
- generalize the ProgressFunc doc comment to note operation-defined units
- update the existing call site in flasher_test.go
- add tests: tickMD5 direct (monotonic ticks, final call, error path, panic
  path, no goroutine leak) plus end-to-end wiring through the mock connection
@deadprogram

Copy link
Copy Markdown
Member

More progress! 😄

Thanks for the addition @jgangemi now merging.

@deadprogram
deadprogram merged commit 7bdba31 into tinygo-org:main Jul 11, 2026
3 checks passed
@jgangemi
jgangemi deleted the jae/md5-progress branch July 20, 2026 04:17
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.

2 participants