Skip to content

Commit f28d836

Browse files
committed
Fix racing
1 parent ebd94eb commit f28d836

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Core/Sources/SuggestionService/CodeiumSuggestionProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
import Preferences
44
import SuggestionModel
55

6-
final class CodeiumSuggestionProvider: SuggestionServiceProvider {
6+
actor CodeiumSuggestionProvider: SuggestionServiceProvider {
77
let projectRootURL: URL
88
let onServiceLaunched: (SuggestionServiceType) -> Void
99
var codeiumService: CodeiumSuggestionServiceType?

Core/Sources/SuggestionService/GitHubCopilotSuggestionProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import GitHubCopilotService
33
import Preferences
44
import SuggestionModel
55

6-
final class GitHubCopilotSuggestionProvider: SuggestionServiceProvider {
6+
actor GitHubCopilotSuggestionProvider: SuggestionServiceProvider {
77
let projectRootURL: URL
88
let onServiceLaunched: (SuggestionServiceType) -> Void
99
var gitHubCopilotService: GitHubCopilotSuggestionServiceType?

Core/Sources/SuggestionService/SuggestionService.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public protocol SuggestionServiceType {
2727

2828
protocol SuggestionServiceProvider: SuggestionServiceType {}
2929

30-
public final class SuggestionService: SuggestionServiceType {
30+
public actor SuggestionService: SuggestionServiceType {
3131
let projectRootURL: URL
3232
let onServiceLaunched: (SuggestionServiceType) -> Void
3333
let providerChangeObserver = UserDefaultsObserver(
@@ -47,8 +47,10 @@ public final class SuggestionService: SuggestionServiceType {
4747
self.onServiceLaunched = onServiceLaunched
4848

4949
providerChangeObserver.onChange = { [weak self] in
50-
guard let self else { return }
51-
suggestionProvider = buildService()
50+
Task { [weak self] in
51+
guard let self else { return }
52+
await rebuildService()
53+
}
5254
}
5355
}
5456

@@ -66,6 +68,10 @@ public final class SuggestionService: SuggestionServiceType {
6668
)
6769
}
6870
}
71+
72+
func rebuildService() {
73+
suggestionProvider = buildService()
74+
}
6975
}
7076

7177
public extension SuggestionService {

0 commit comments

Comments
 (0)