Skip to content

The problem with async load/subscribe #80

Answered by mbrandonw
tevelee asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @tevelee, it simply wreaks havoc on testing. You would not even be able to do something as simple as:

@Test func basics() {
  UserDefaults.standard.set(42, forKey: "count")
  @Shared(.appStorage("count")) var count = 0
  #expect(count == 42)  // ❌ Expected 42, actual 0.
}

…because load is async. You would need to insert Task.sleep around every usage of the shared value.

Additionally, the subscribe method does not utilize TaskGroup.

FWIW, that is not the shape subscribe would have. It would instead need to return an any AsyncSequence.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tevelee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants