Use coroutine to fetch flight data off main thread#9
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| fun stopScan() { | ||
| handler.removeCallbacksAndMessages(null) | ||
| context.unregisterReceiver(receiver) | ||
| scope.cancel() |
There was a problem hiding this comment.
[P1] Recreate CoroutineScope after cancellation
Because the scope is a single CoroutineScope(SupervisorJob() + Dispatchers.IO) stored as a val, calling stopScan() cancels that scope permanently. Any subsequent call to startScan() will try to scope.launch { … } on a cancelled scope and the coroutine will immediately cancel, so fetchFlightData() never runs after the first stop. If this detector is started and stopped repeatedly during the app lifecycle, scanning cannot resume. Consider creating a new scope when starting or cancelling only the active job instead of the whole scope.
Useful? React with 👍 / 👎.
Summary
fetchFlightDataa suspend functionfetchFlightDataonDispatchers.IOwithinstartScanstopScanTesting
./gradlew test(fails: No such file or directory)https://chatgpt.com/codex/tasks/task_e_68c331bc0e8c8328b6c6b391aba554d1