Skip to content

Commit

Permalink
fix: change from unowned self to weak self
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Oct 18, 2024
1 parent b373963 commit d037c6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Sources/VRCKit/Services/FavoriteService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
public func listFavorites(type: FavoriteType) async throws -> [Favorite] {
try await withThrowingTaskGroup(of: [Favorite].self) { taskGroup in
for offset in [0, 100, 200, 300] {
taskGroup.addTask { [unowned self] in
try await listFavorites(n: 100, offset: offset, type: type)
taskGroup.addTask { [weak self] in
guard let self = self else { return [] }
return try await listFavorites(n: 100, offset: offset, type: type)
}
}
var results: [Favorite] = []
Expand Down Expand Up @@ -71,8 +72,14 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
public func fetchFavoriteList(favoriteGroups: [FavoriteGroup], type: FavoriteType) async throws -> [FavoriteList] {
try await withThrowingTaskGroup(of: FavoriteList.self) { taskGroup in
for favoriteGroup in favoriteGroups.filter({ $0.type == type }) {
taskGroup.addTask { [unowned self] in
FavoriteList(
taskGroup.addTask { [weak self] in
guard let self = self else {
return FavoriteList(
id: favoriteGroup.id,
favorites: []
)
}
return FavoriteList(
id: favoriteGroup.id,
favorites: try await listFavorites(type: type, tag: favoriteGroup.name)
)
Expand Down
3 changes: 2 additions & 1 deletion Sources/VRCKit/Services/WorldService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public final actor WorldService: APIService, WorldServiceProtocol {
public func fetchFavoritedWorlds() async throws -> [FavoriteWorld] {
try await withThrowingTaskGroup(of: FavoriteWorldsWithOffset.self) { taskGroup in
for offset in Array(stride(from: 0, to: maxCount, by: limit)) {
taskGroup.addTask { [unowned self] in
taskGroup.addTask { [weak self] in
guard let self = self else { return (offset, []) }
let worlds = try await fetchFavoritedWorlds(n: limit, offset: offset)
return (offset, worlds)
}
Expand Down

0 comments on commit d037c6f

Please sign in to comment.