heckj / swiftui-notes

content for Using Combine - notes on learning Combine with UIKit and SwiftUI
https://heckj.github.io/swiftui-notes/
MIT License
1.97k stars 204 forks source link

Multicast/Share idiosyncracies #217

Closed iwillau closed 4 years ago

iwillau commented 4 years ago

Hey Mate,

I just forked your repository to illustrate a use-case for multicast/share, where you can insert a subscriber into a system that's already working.

I used this in one of my projects to intercept all requests to DataTask and cache the results, concurrently and independently to the subscriber in my ViewModels. I didn't have to co-ordinate a call to connect or anything like that.

In addition I didn't realise (for quite some time) that you could subscribe to a 'share' or multicast and if you missed the value (because the original subscriber called send before your intercept code was ready), then it was just too bad, but you still received a 'completion'!

Anyway, I am aware I haven't conformed to your current coding style etc. If you're interested I can tidy it up/conform prior to merging, but I didn't want to do the work if I've just figured out something dumb .... or more likely, you point out the massive glaring problem with what I've done!

Thanks for the book/repo anyway, it's always kept handy when I'm coding!

Will.

heckj commented 4 years ago

Thank you Will, I'll happily take a look at the submission. And don't worry about style as such - I'm far from "mr consistent" in how I approach things, so as long as it's understandable and people can see how to it works and how they can use it themselves, I'd call it a win. (to be fair, I haven't even looked yet - just replying via email to the github notification)

And yeah - linking to the a shared reference can be a real surprise, especially when dealing with Futures that haven't been wrapped in Defer, which optimistically trigger... so you're left wondering WTF just happened and why is it just saying "Yep, done!" happily with no values. The set up (and timing of such) of these can be a real trick!

On Aug 4, 2020, at 6:30 AM, Will Wheatley notifications@github.com wrote:

 Hey Mate,

I just forked your repository to illustrate a use-case for multicast/share, where you can insert a subscriber into a system that's already working.

I used this in one of my projects to intercept all requests to DataTask and cache the results, concurrently and independently to the subscriber in my ViewModels. I didn't have to co-ordinate a call to connect or anything like that.

In addition I didn't realise (for quite some time) that you could subscribe to a 'share' or multicast and if you missed the value (because the original subscriber called send before your intercept code was ready), then it was just too bad, but you still received a 'completion'!

Anyway, I am aware I haven't conformed to your current coding style etc. If you're interested I can tidy it up/conform prior to merging, but I didn't want to do the work if I've just figured out something dumb .... or more likely, you point out the massive glaring problem with what I've done!

Thanks for the book/repo anyway, it's always kept handy when I'm coding!

Will.

You can view, comment on, or merge this pull request online at:

https://github.com/heckj/swiftui-notes/pull/217

Commit Summary

Modified MulticastShare tests to show that latecoming subscribers will be accepted, but won't receive the value. Just the completion. Hopefully I've conveyed a use-case for autoconnect(). Adding a subscriber to a chain without the regular subscribers of the publisher needing to be modified. File Changes

M UsingCombineTests/MulticastSharePublisherTests.swift (185) Patch Links:

https://github.com/heckj/swiftui-notes/pull/217.patch https://github.com/heckj/swiftui-notes/pull/217.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.