Skip to content

Conversation

@aanorbel
Copy link
Member

Closes #399

@aanorbel aanorbel requested a review from sdsantos January 28, 2025 12:43
// https://developer.apple.com/documentation/foundation/nsdate/1410206-timeintervalsince
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

3 participants