Skip to content

Own and dispose app-level stream subscriptions#7

Open
robekl wants to merge 1 commit intoMeshMapper:devfrom
robekl:fix/appstate-own-stream-subscriptions
Open

Own and dispose app-level stream subscriptions#7
robekl wants to merge 1 commit intoMeshMapper:devfrom
robekl:fix/appstate-own-stream-subscriptions

Conversation

@robekl
Copy link

@robekl robekl commented Mar 4, 2026

Summary

Owns and disposes long-lived AppStateProvider stream subscriptions to prevent leaked listeners and duplicate callbacks across provider lifecycle events.

Problem

AppStateProvider created listeners for:

  • Bluetooth connectionStream
  • GPS statusStream
  • GPS positionStream

but did not keep/cancel those subscriptions explicitly in dispose().
That can cause lingering listeners and repeated state updates after re-init/hot-reload/provider recreation.

Changes

  • Added subscription fields:
    • _connectionSubscription
    • _gpsStatusSubscription
    • _gpsPositionSubscription
  • In _initialize():
    • cancel existing subscription before re-subscribing for each stream
    • store new subscription handles
  • In dispose():
    • explicitly cancel all three new subscriptions

Why this works

All app-level stream listeners are now lifecycle-owned by the provider instance and deterministically cancelled at teardown.

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