Skip to content

Move airport fetch to background context in WeatherViewModel#5

Merged
RISCfuture merged 1 commit intomainfrom
fix/weather-viewmodel-background-fetch
Apr 12, 2026
Merged

Move airport fetch to background context in WeatherViewModel#5
RISCfuture merged 1 commit intomainfrom
fix/weather-viewmodel-background-fetch

Conversation

@RISCfuture
Copy link
Copy Markdown
Contributor

Summary

  • Contributes to fixing SF50-TOLD-1X (DB on main thread)
  • Switches `setupObservation()` from `Task {}` (inherits `@MainActor`) to `Task.detached`
  • Uses a fresh `ModelContext(container)` per iteration, sets `self.airport` back on `MainActor` via `await MainActor.run`
  • Preserves the existing `didSet` observer that triggers `subscribe()` on the main actor

Test plan

  • Unit tests (SF50 Shared Unit Tests) pass
  • UI tests (47 tests, SF50 TOLD UI Tests) pass
  • swift format + swiftlint clean

🤖 Generated with Claude Code

Contributes to fixing SF50-TOLD-1X (DB on main thread). The
setupObservation() method used Task {} which inherits @mainactor,
so container.mainContext fetches ran on the main thread.

Switches to Task.detached with a fresh ModelContext(container) per
iteration, setting self.airport back on MainActor via await
MainActor.run. This preserves the existing didSet observer that
triggers subscribe() on the main actor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@RISCfuture RISCfuture merged commit b36ac95 into main Apr 12, 2026
10 checks passed
@RISCfuture RISCfuture deleted the fix/weather-viewmodel-background-fetch branch April 12, 2026 20:44
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