I have a question about how the following would behave, and if it's safe.
in the following scenario... would initialFetch....
a) always be toggled once to False?
b) would the thing that toggles it always be the first task to initialize a MyFeedItem?
because if each task in executing on some unknown thread, could two of these complete the initialization of MyFeedItem at the same time?
class Feed: ObservableObject {
var initialFetch = True
@Published var items = [FeedItem]()
func fetchFeed() async {
// fetches a list of feed items from API
feedItems.forEach { [itemInResponse]
Task {
// async creates feed items because we do not care about an item until the image is fetched (in
// the MyFeedItem init
let myItem = await MyFeedItem(...)
// HERE IS THE QUESTION
if initialFetch {
initialFetch.toggle()
await initialFetchDependentUILogic(item: myItem)
}
await addItem(item)
}
}
}
@MainActor
func addItem(_ item: FeedItem) async {
items.append(item)
}
@MainActor
func initialFetchDependentUILogic(item: FeedItem) {
// logic that changes UI
}
}