Skip to content

Use coroutine to fetch flight data off main thread#9

Merged
nbschultz97 merged 1 commit intomainfrom
codex/convert-fetchflightdata-to-suspend-function
Sep 12, 2025
Merged

Use coroutine to fetch flight data off main thread#9
nbschultz97 merged 1 commit intomainfrom
codex/convert-fetchflightdata-to-suspend-function

Conversation

@nbschultz97
Copy link
Owner

Summary

  • Make fetchFlightData a suspend function
  • Launch fetchFlightData on Dispatchers.IO within startScan
  • Cancel coroutine scope on stopScan

Testing

  • ./gradlew test (fails: No such file or directory)

https://chatgpt.com/codex/tasks/task_e_68c331bc0e8c8328b6c6b391aba554d1

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment on lines 33 to +36
fun stopScan() {
handler.removeCallbacksAndMessages(null)
context.unregisterReceiver(receiver)
scope.cancel()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 👍 / 👎.

@nbschultz97 nbschultz97 merged commit 264691b into main Sep 12, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant