Replace iterators with callbacks for progress reporting.#340
Open
Replace iterators with callbacks for progress reporting.#340
Conversation
mirkoCrobu
reviewed
Apr 8, 2026
mirkoCrobu
reviewed
Apr 8, 2026
Comment on lines
-57
to
+60
| for appStatus, err := range orchestrator.AppStatusEvents(r.Context(), cfg, dockerCli, idProvider) { | ||
| if err != nil { | ||
| sseStream.SendError(render.SSEErrorData{Code: render.InternalServiceErr, Message: err.Error()}) | ||
| continue | ||
| } | ||
| if err := orchestrator.AppStatusEvents(r.Context(), cfg, dockerCli, idProvider, func(appStatus orchestrator.AppInfo) { | ||
| sseStream.Send(render.SSEEvent{Type: "app", Data: appStatus}) | ||
| }); err != nil { | ||
| sseStream.SendError(render.SSEErrorData{Code: render.InternalServiceErr, Message: err.Error()}) |
Contributor
There was a problem hiding this comment.
what happen now if appstatusEvents returns an error? With iterators, there was a continue, and the SSE streaming stayed alive. Now any error terminate the session?
* internal/orchestrator/orchestrator.go:
- Removed "iter" import
- StartApp, stopAppWithCmd, StopApp, StopAndDestroyApp, cleanAppCacheFiles, RestartApp: changed from returning iter.Seq[StreamMessage] to accepting a cb func(StreamMessage)
parameter
- All yield(msg) calls replaced with cb(msg), and if !yield(msg) { return } patterns simplified to just cb(msg) (early cancellation now relies purely on context)
- StartDefaultApp and DeleteApp: updated internal calls to pass a callback
- RestartApp: uses a stopHadError flag to avoid starting if stop failed
* Callers updated to pass a callback instead of ranging over the iterator:
- internal/api/handlers/app_start.go and app_stop.go
- cmd/arduino-app-cli/app/start.go, stop.go, restart.go, destroy.go
- internal/orchestrator/system.go, cache.go, models.go
- AppStatusEvents now has the signature `func(..., cb func(AppInfo)) error` - The callback only receives the happy-path AppInfo, and any error is returned directly to the caller. - Updated the caller in internal/api/handlers/app_status.go to pass a callback (the old continue becomes a return in the callback body) The old error handling in the streaming phase, is now handled at function exit.
- AppLogs now takes cb func(LogMessage) as last param and returns error - DockerLogConsumer.cb changed from `func(LogMessage) bool` to `func(LogMessage)` - Removed shuttingDown atomic.Bool (the double-check lock for early-stop signalling is no longer needed) - Removed "iter", "sync/atomic", and helpers imports
- SystemResources now takes `cb func(SystemResource)` as last param and
returns `error`.
- All `if !yield(msg) { return }` patterns simplified to `cb(msg)`.
- Removed "iter" and helpers imports.
- NewSSEClient now takes `cb func(Event)` and returns `error` - Context cancellation errors treated as nil (normal termination) - `waitForUpgrade` uses `context.WithCancel` + `cancel()` inside the callback to replace the old break - Made NewSSEClient private
- runUpgradeCommand, runAptCleanCommand, pullDockerImages, cleanupDockerContainers all changed from returning `iter.Seq2[string, error]` to `func(..., cb func(string)) error` - Process kill-on-stop logic removed (context cancellation handles it) - UpgradePackages caller updated accordingly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
This pull request refactors the way streaming and event-based APIs are handled throughout the codebase, moving from iterator-based interfaces to callback-based ones. This change simplifies the control flow, improves error handling, and removes the dependency on the
iterpackage. Additionally, related test helpers and internal utilities were updated to match the new approach.Change description
Test and helper code updates:
Dependency and code cleanup:
iter.gohelper and all uses of theiterpackage, since the new callback-based approach makes these utilities unnecessary.Additional Notes
Reviewer checklist
main.