Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(iOS): restructure background task #424

Merged
merged 4 commits into from
Jan 30, 2025
Merged

chore(iOS): restructure background task #424

merged 4 commits into from
Jan 30, 2025

Conversation

aanorbel
Copy link
Member

Closes #399

@aanorbel aanorbel requested a review from sdsantos January 28, 2025 12:43
fun startSingleRun(spec: RunSpecification) {
val startDateTime = NSDate()
val differed = CoroutineScope(Dispatchers.Default).async {
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean deferred? 😄

// End the task if time expires.
UIApplication.shared.endBackgroundTask(self.backgroundTask)
self.backgroundTask = UIBackgroundTaskIdentifier.invalid
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe call it onCancel? The first time I read it I thought it was a method to cancel the task, instead of an event callback.

differed.start()
}, cancel = {
differed.cancel()
Logger.i { "Job cancelled after ${NSDate().timeIntervalSinceDate(startDateTime)} ms" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger.i will only log as a breadcrumb. This only gets sent if there's an error. Or will we always call line 26 inside the catch when it's aborted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope only on error.

@aanorbel aanorbel merged commit 9dc8f64 into main Jan 30, 2025
7 checks passed
@aanorbel aanorbel deleted the issues/399 branch January 30, 2025 07:36
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.

[iOS] Report to Sentry when our background services are killed by the operative system
2 participants