-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor FXIOS-10924 - Remove Deferred from FolderHierarchyFetcher #23900
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,22 +35,23 @@ struct DefaultFolderHierarchyFetcher: FolderHierarchyFetcher, BookmarksRefactorF | |
|
||
func fetchFolders() async -> [Folder] { | ||
let numDesktopBookmarks = await countDesktopBookmarks() | ||
return await withCheckedContinuation { continuation in | ||
profile.places.getBookmarksTree(rootGUID: rootFolderGUID, | ||
recursive: true).uponQueue(.main) { data in | ||
var folders = [Folder]() | ||
defer { | ||
continuation.resume(returning: folders) | ||
} | ||
guard let rootFolder = data.successValue as? BookmarkFolderData else { return } | ||
let hasDesktopBookmarks = (numDesktopBookmarks ?? 0) > 0 | ||
|
||
let childrenFolders = rootFolder.children?.compactMap { | ||
return $0 as? BookmarkFolderData | ||
} | ||
return await withUnsafeContinuation { continuation in | ||
profile.places.getBookmarksTree(rootGUID: rootFolderGUID, recursive: true) { result in | ||
switch result { | ||
case .success(let data): | ||
guard let rootFolder = data as? BookmarkFolderData else { return } | ||
let hasDesktopBookmarks = (numDesktopBookmarks ?? 0) > 0 | ||
|
||
for folder in childrenFolders ?? [] { | ||
recursiveAddSubFolders(folder, folders: &folders, hasDesktopBookmarks: hasDesktopBookmarks) | ||
let childrenFolders = rootFolder.children?.compactMap { | ||
return $0 as? BookmarkFolderData | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also don't call the continuation here now either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see, on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops yeah you're right that this one is in a compactMap, but yeah the guard one is a problem! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or just call the continuation in the guard would be reasonable, whichever you prefer! If you use a defer, can you please check that the continuation doesn't get called twice with a breakpoint if possible? Since the |
||
} | ||
var folders = [Folder]() | ||
for folder in childrenFolders ?? [] { | ||
recursiveAddSubFolders(folder, folders: &folders, hasDesktopBookmarks: hasDesktopBookmarks) | ||
} | ||
continuation.resume(returning: folders) | ||
case .failure: | ||
continuation.resume(returning: []) | ||
} | ||
} | ||
} | ||
|
@@ -75,7 +76,7 @@ struct DefaultFolderHierarchyFetcher: FolderHierarchyFetcher, BookmarksRefactorF | |
} | ||
|
||
private func countDesktopBookmarks() async -> Int? { | ||
return await withCheckedContinuation { continuation in | ||
return await withUnsafeContinuation { continuation in | ||
profile.places.countBookmarksInTrees(folderGuids: BookmarkRoots.DesktopRoots.map { $0 }) { result in | ||
switch result { | ||
case .success(let count): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @PARAIPAN9 ! @lmarceau just wanted me to take a peek at the continuations.
There's a chance we miss calling continuation.resume here in the guard return since we don't have
defer
anymore. Are we explicitly removingdefer
s as well as theDeferred
?