mattgallagher / CwlSignal

A Swift framework for reactive programming.
ISC License
303 stars 33 forks source link

Question: On capture blocking signal delivery #1

Closed bobspryn closed 7 years ago

bobspryn commented 7 years ago

Hey Matt!

Not sure if you are cool with questions here, but here's mine. :)

In your post introducing CwlSignal you talk about capturing. I see that using that operator captures the activation values. I see that you can access those using the activation() method, but I'm unclear why doing so blocks future signal delivery.

Cool looking library so far!

mattgallagher commented 7 years ago

The reason why the pausing (called a holdCount in the code) is necessary is to ensure that while you're handling the activation values from the SignalCapture, you don't miss the next values in the sequence that might be delivered from another thread. In sequence delivery with no lost values is the primary requirement of reactive programming.

I should clarify that it's only the branch of the graph that travels through your own SignalCapture node that is paused (any other listeners won't be paused). Values travelling through the SignalCapture branch are simply queued until you connect somewhere for them to go.

bobspryn commented 7 years ago

Interesting. I think I would have suspected the default behavior to be capturing the activation values, but then allowing the signal behavior to pass through. For instance, since your output signal was continuous in your example, I would have expected to only see the value 4 once I subscribed (with the activation value of 2). But capture seems to almost change it to a replay type after capturing activation values.