Skip to content

Commit 6d824f5

Browse files
committed
No async required to make CachedAndFetchedResult
1 parent 045a740 commit 6d824f5

File tree

8 files changed

+29
-42
lines changed

8 files changed

+29
-42
lines changed

Modules/Sources/Support/InternalDataProvider.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,13 @@ actor InternalBotConversationDataProvider: BotConversationDataProvider {
273273
await SupportDataProvider.supportUser
274274
}
275275

276-
func loadBotConversations() async throws -> any CachedAndFetchedResult<[BotConversation]> {
276+
nonisolated func loadBotConversations() throws -> any CachedAndFetchedResult<[BotConversation]> {
277277
UncachedResult {
278278
[await SupportDataProvider.botConversation]
279279
}
280280
}
281281

282-
func loadBotConversation(id: UInt64) async throws -> any CachedAndFetchedResult<BotConversation> {
282+
nonisolated func loadBotConversation(id: UInt64) throws -> any CachedAndFetchedResult<BotConversation> {
283283
UncachedResult {
284284
if id == 5678 {
285285
return await SupportDataProvider.conversationReferredToHuman
@@ -315,7 +315,7 @@ actor InternalBotConversationDataProvider: BotConversationDataProvider {
315315
}
316316

317317
actor InternalUserDataProvider: CurrentUserDataProvider {
318-
func fetchCurrentSupportUser() async throws -> any CachedAndFetchedResult<SupportUser> {
318+
nonisolated func fetchCurrentSupportUser() throws -> any CachedAndFetchedResult<SupportUser> {
319319
UncachedResult {
320320
await SupportDataProvider.supportUser
321321
}
@@ -325,13 +325,13 @@ actor InternalUserDataProvider: CurrentUserDataProvider {
325325
actor InternalSupportConversationDataProvider: SupportConversationDataProvider {
326326
private var conversations: [UInt64: Conversation] = [:]
327327

328-
func loadSupportConversations() async throws -> any CachedAndFetchedResult<[ConversationSummary]> {
328+
nonisolated func loadSupportConversations() throws -> any CachedAndFetchedResult<[ConversationSummary]> {
329329
UncachedResult {
330330
return await SupportDataProvider.supportConversationSummaries
331331
}
332332
}
333333

334-
func loadSupportConversation(id: UInt64) async throws -> any CachedAndFetchedResult<Conversation> {
334+
nonisolated func loadSupportConversation(id: UInt64) throws -> any CachedAndFetchedResult<Conversation> {
335335
UncachedResult {
336336
let conversation = await SupportDataProvider.supportConversation
337337
await self.cache(conversation)

Modules/Sources/Support/SupportDataProvider.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ public final class SupportDataProvider: ObservableObject, Sendable {
4949
}
5050

5151
// Support Bots Data Source
52-
public func loadSupportIdentity() async throws -> any CachedAndFetchedResult<SupportUser> {
53-
try await self.userDataProvider.fetchCurrentSupportUser()
52+
public func loadSupportIdentity() throws -> any CachedAndFetchedResult<SupportUser> {
53+
try self.userDataProvider.fetchCurrentSupportUser()
5454
}
5555

5656
// Bot Conversation Data Source
5757
public func loadConversations() async throws -> any CachedAndFetchedResult<[BotConversation]> {
58-
try await self.botConversationDataProvider.loadBotConversations()
58+
try self.botConversationDataProvider.loadBotConversations()
5959
}
6060

6161
public func loadConversation(id: UInt64) async throws -> any CachedAndFetchedResult<BotConversation> {
62-
try await self.botConversationDataProvider.loadBotConversation(id: id)
62+
try self.botConversationDataProvider.loadBotConversation(id: id)
6363
}
6464

6565
public func delete(conversationIds: [UInt64]) async throws {
@@ -71,12 +71,12 @@ public final class SupportDataProvider: ObservableObject, Sendable {
7171
}
7272

7373
// Support Conversations Data Source
74-
public func loadSupportConversations() async throws -> any CachedAndFetchedResult<[ConversationSummary]> {
75-
try await self.supportConversationDataProvider.loadSupportConversations()
74+
public func loadSupportConversations() throws -> any CachedAndFetchedResult<[ConversationSummary]> {
75+
try self.supportConversationDataProvider.loadSupportConversations()
7676
}
7777

78-
public func loadSupportConversation(id: UInt64) async throws -> any CachedAndFetchedResult<Conversation> {
79-
try await self.supportConversationDataProvider.loadSupportConversation(id: id)
78+
public func loadSupportConversation(id: UInt64) throws -> any CachedAndFetchedResult<Conversation> {
79+
try self.supportConversationDataProvider.loadSupportConversation(id: id)
8080
}
8181

8282
public func replyToSupportConversation(
@@ -171,7 +171,7 @@ public enum SupportUserPermission: Sendable, Codable {
171171
}
172172

173173
public protocol CurrentUserDataProvider: Actor {
174-
func fetchCurrentSupportUser() async throws -> any CachedAndFetchedResult<SupportUser>
174+
nonisolated func fetchCurrentSupportUser() throws -> any CachedAndFetchedResult<SupportUser>
175175
}
176176

177177
public protocol ApplicationLogDataProvider: Actor {
@@ -194,16 +194,16 @@ public extension ApplicationLogDataProvider {
194194
}
195195

196196
public protocol BotConversationDataProvider: Actor {
197-
func loadBotConversations() async throws -> any CachedAndFetchedResult<[BotConversation]>
198-
func loadBotConversation(id: UInt64) async throws -> any CachedAndFetchedResult<BotConversation>
197+
nonisolated func loadBotConversations() throws -> any CachedAndFetchedResult<[BotConversation]>
198+
nonisolated func loadBotConversation(id: UInt64) throws -> any CachedAndFetchedResult<BotConversation>
199199

200200
func sendMessage(message: String, in conversation: BotConversation?) async throws -> BotConversation
201201
func delete(conversationIds: [UInt64]) async throws
202202
}
203203

204204
public protocol SupportConversationDataProvider: Actor {
205-
func loadSupportConversations() async throws -> any CachedAndFetchedResult<[ConversationSummary]>
206-
func loadSupportConversation(id: UInt64) async throws -> any CachedAndFetchedResult<Conversation>
205+
nonisolated func loadSupportConversations() throws -> any CachedAndFetchedResult<[ConversationSummary]>
206+
nonisolated func loadSupportConversation(id: UInt64) throws -> any CachedAndFetchedResult<Conversation>
207207

208208
func replyToSupportConversation(
209209
id: UInt64,

Modules/Sources/Support/UI/Application Logs/ActivityLogListView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public struct ActivityLogListView: View {
165165

166166
#Preview {
167167
NavigationStack {
168-
ActivityLogListView() .environmentObject(SupportDataProvider.testing)
169-
168+
ActivityLogListView().environmentObject(SupportDataProvider.testing)
170169
}
171170
}

Modules/Sources/Support/UI/Bot Conversations/ConversationListView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,13 @@ public struct ConversationListView: View {
149149
let fetch = try await dataProvider.loadConversations()
150150

151151
if let cachedConversations = try await fetch.cachedResult() {
152-
debugPrint("💬 Finished fetching cached conversations")
153-
154152
await MainActor.run {
155153
self.state = .partiallyLoaded(cachedConversations)
156154
}
157155
}
158156

159157
let fetchedConversations = try await fetch.fetchedResult()
160158

161-
debugPrint("💬 Finished fetching conversations")
162-
163159
await MainActor.run {
164160
self.state = .loaded(fetchedConversations, .none)
165161
}

Modules/Sources/Support/UI/Support Conversations/SupportConversationListView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public struct SupportConversationListView: View {
107107

108108
private func loadConversations() async {
109109
do {
110-
let fetch = try await dataProvider.loadSupportConversations()
110+
let fetch = try dataProvider.loadSupportConversations()
111111

112112
if let cachedResults = try await fetch.cachedResult() {
113113
await MainActor.run {

Modules/Sources/Support/UI/Support Conversations/SupportConversationView.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,15 @@ public struct SupportConversationView: View {
204204
do {
205205
let conversationId = self.conversationSummary.id
206206

207-
let fetch = try await self.dataProvider.loadSupportConversation(id: conversationId)
207+
let fetch = try self.dataProvider.loadSupportConversation(id: conversationId)
208208

209209
if let cached = try await fetch.cachedResult() {
210-
debugPrint("💬 Finished fetching cached conversations")
211-
212210
await MainActor.run {
213211
self.state = .partiallyLoaded(cached)
214212
}
215213
}
216214

217-
if Task.isCancelled {
218-
preconditionFailure("need to handle cancellation!")
219-
}
220-
221215
let conversation = try await fetch.fetchedResult()
222-
debugPrint("💬 Finished fetching cached conversations")
223-
224216
await MainActor.run {
225217
self.state = .loaded(conversation)
226218
}

Modules/Sources/Support/UI/Support Conversations/SupportForm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private extension SupportForm {
269269

270270
Task {
271271
do {
272-
let conversation = try await self.dataProvider.createSupportConversation(
272+
_ = try await self.dataProvider.createSupportConversation(
273273
subject: self.subject,
274274
message: self.getText(),
275275
user: self.supportIdentity,

WordPress/Classes/ViewRelated/NewSupport/SupportDataProvider.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ actor WpBotConversationDataProvider: BotConversationDataProvider {
6666
self.wpcomClient = wpcomClient
6767
}
6868

69-
func loadBotConversations() async throws -> any CachedAndFetchedResult<[Support.BotConversation]> {
70-
return DiskCachedAndFetchedResult(fetchedResult: {
69+
nonisolated func loadBotConversations() throws -> any CachedAndFetchedResult<[Support.BotConversation]> {
70+
DiskCachedAndFetchedResult(fetchedResult: {
7171
try await self.wpcomClient
7272
.api
7373
.supportBots
@@ -77,7 +77,7 @@ actor WpBotConversationDataProvider: BotConversationDataProvider {
7777
}, cacheKey: "bot-conversation-list")
7878
}
7979

80-
func loadBotConversation(id: UInt64) async throws -> any CachedAndFetchedResult<Support.BotConversation> {
80+
nonisolated func loadBotConversation(id: UInt64) throws -> any CachedAndFetchedResult<Support.BotConversation> {
8181
return DiskCachedAndFetchedResult(fetchedResult: {
8282
let params = GetBotConversationParams(
8383
pageNumber: 1,
@@ -156,8 +156,8 @@ actor WpCurrentUserDataProvider: CurrentUserDataProvider {
156156
self.wpcomClient = wpcomClient
157157
}
158158

159-
func fetchCurrentSupportUser() async throws -> any CachedAndFetchedResult<Support.SupportUser> {
160-
return DiskCachedAndFetchedResult(fetchedResult: {
159+
nonisolated func fetchCurrentSupportUser() throws -> any CachedAndFetchedResult<Support.SupportUser> {
160+
DiskCachedAndFetchedResult(fetchedResult: {
161161
async let user = try await self.wpcomClient.api.me.get().data.asSupportIdentity()
162162
async let eligibility = try await self.wpcomClient.api.supportEligibility.getSupportEligibility().data
163163

@@ -175,7 +175,7 @@ actor WpSupportConversationDataProvider: SupportConversationDataProvider {
175175
self.wpcomClient = wpcomClient
176176
}
177177

178-
func loadSupportConversations() async throws -> any CachedAndFetchedResult<[ConversationSummary]> {
178+
nonisolated func loadSupportConversations() throws -> any CachedAndFetchedResult<[ConversationSummary]> {
179179
return DiskCachedAndFetchedResult(fetchedResult: {
180180
try await self.wpcomClient.api
181181
.supportTickets
@@ -185,7 +185,7 @@ actor WpSupportConversationDataProvider: SupportConversationDataProvider {
185185
}, cacheKey: "support-conversation-list")
186186
}
187187

188-
func loadSupportConversation(id: UInt64) async throws -> any CachedAndFetchedResult<Conversation> {
188+
nonisolated func loadSupportConversation(id: UInt64) throws -> any CachedAndFetchedResult<Conversation> {
189189
return DiskCachedAndFetchedResult(fetchedResult: {
190190
try await self.wpcomClient.api
191191
.supportTickets

0 commit comments

Comments
 (0)