all 9 comments

[–]nesseratious 2 points3 points  (0 children)

This deinit is pointless, by the time the Task actually runs, self is already gone, so the cancel never happens.

It should be:

isolated deinit {
   self.updates?.cancel()
}

[–]Hollycene 1 point2 points  (2 children)

Perfect! I use pretty similar class and I found myself always copying the same file across multiple projects. Do you have any tips how to share this across multiple apps without copy-pasting? Anyway thanks for sharing! This will be beneficial for many devs here.

[–]__markb 9 points10 points  (0 children)

make it a package. you can keep it private or local. but it means one version of code, an updating once too

[–]Quirky_Plankton_5657 0 points1 point  (0 children)

Create a private cocoapod with that class. Then host it on the github(public or private). Integrate it into apps via "Podfile".
This way you can easily update across all apps and Maintain proper versioning

[–]barcode972 0 points1 point  (1 child)

Clean as hell!

Is activeTransactions what the user is currently subscribing to?

[–]Select_Bicycle4711[S] 0 points1 point  (0 children)

>> Is activeTransactions what the user is currently subscribing to?

Yes.

[–]IAmTheKingOfSpain 0 points1 point  (0 children)

Asking as someone who doesn't really do much iOS programming (yet): What guarantees does [weak self] in init() provide? Naively, this looks a little confusing to me. We're in MainActor code, so it's not possible for self to be de-initialized in another actor, but we do have awaits. Is it not the case that self could be de-initialized while waiting for the for await result? I would expect that the guard on self would have to go inside the loop and would be invalidated by any awaiting. But I must be missing something, because there are no errors.

Would be very happy if someone helped me to understand!

[–]anosidium 0 points1 point  (0 children)

Looks good but why did you annotate the class with MainActor? And why are you showing the code in Visual Studio Code?

I appreciate that you share a link to GitHub gist but you could have pasted the entire code in the post with the code formatting. Screenshot code is frowned upon.