Skip to content

Stop torrent status polling from outliving its screen#478

Open
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/viewmodel-polling-scopes
Open

Stop torrent status polling from outliving its screen#478
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/viewmodel-polling-scopes

Conversation

@ElCruncharino

Copy link
Copy Markdown
Contributor

TorrentDetailsViewModel and TorrentProcessingViewModel each created their own CoroutineScope for polling torrent status instead of using viewModelScope, and nothing ever cancelled it if you navigated away before the polling loop's own stop condition was reached. That left it polling the API in the background indefinitely, using battery and data with no way for the user to know why. Switched both to viewModelScope, which gets cancelled automatically when the screen is left.

TorrentDetailsViewModel.pollTorrentStatus and TorrentProcessingViewModel.startSelectionLoop each built their own CoroutineScope backed by a plain Job, completely separate from the ViewModel lifecycle. When the user navigated away before the loop's own stop condition fired, the coroutine kept running because nothing ever cancelled it (there is no onCleared override anywhere in the codebase). Both loops now launch on viewModelScope instead, so clearing the ViewModel cancels them automatically. The job field is kept as a nullable handle purely so a new call can cancel a previous in-flight loop and so the loop can stop itself once the tracked status reaches an end state, same as before.
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