Skip to content

Commit

Permalink
feat: MacOS support for ExpiringActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Feb 1, 2024
1 parent 5ded5cd commit 8b9492f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Sources/InfomaniakCore/Background/ExpiringActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,20 @@ public final class ExpiringActivity: ExpiringActivityable {
self.locks.append(group)
}

let processInfo = ProcessInfo.processInfo
#if os(macOS)
processInfos.performActivity(options: .suddenTerminationDisabled, reason: taskName) {
guard let self else {
return
}

// No expiration handler as we are running on macOS
group.enter()
group.wait()
}
#else
// Make sure to not lock an unexpected thread that would deinit()
ProcessInfo.processInfo.performExpiringActivity(withReason: id) { [weak self] shouldTerminate in
processInfo.performExpiringActivity(withReason: id) { [weak self] shouldTerminate in
guard let self else {
return
}
Expand All @@ -96,6 +108,7 @@ public final class ExpiringActivity: ExpiringActivityable {
group.enter()
group.wait()
}
#endif
}

public func endAll() {
Expand Down

0 comments on commit 8b9492f

Please sign in to comment.