rehansaeed.github.io
rehansaeed.github.io copied to clipboard
[Comment] Reactive Extensions (Rx) - Part 1 - Replacing C# Events
https://rehansaeed.com/reactive-extensions-part1-replacing-events/
jacob commented on 2014-12-23 17:06:30
Great blog! thanks for the help, makes alot more sense now
Abhinav Singh commented on 2015-03-06 17:58:38
public void SpotPlane(JetFighter jetFighter)
{
try
{
if (string.Equals(jetFighter.Name, "UFO"))
{
throw new Exception("UFO Found")
}
this.planeSpotted.OnNext(foo);
}
catch (Exception exception)
{
this.planeSpotted.OnError(exception);
}
}
In above code, we should have this.planeSpotted.OnNext(jetFighter); instead of this.planeSpotted.OnNext(foo);?
My understanding is correct?
Please reply
Muhammad Rehan Saeed commented on 2015-03-06 19:15:57
public void SpotPlane(JetFighter jetFighter) { try { if (string.Equals(jetFighter.Name, "UFO")) { throw new Exception("UFO Found") } this.planeSpotted.OnNext(foo); } catch (Exception exception) { this.planeSpotted.OnError(exception); } }In above code, we should have
this.planeSpotted.OnNext(jetFighter);instead ofthis.planeSpotted.OnNext(foo);? My understanding is correct? Please reply
Yes that's correct. I've now corrected it.
Sam commented on 2016-08-17 15:45:07
When is this called?
public void AllPlanesSpotted()
{
this.planeSpotted.OnCompleted();
}
Muhammad Rehan Saeed commented on 2016-08-19 09:18:50
When is this called?
public void AllPlanesSpotted() { this.planeSpotted.OnCompleted(); }
I'm just trying to illustrate that observables can have an end, so that no more events are allowed to be raised. It could be called from anywhere.
Andrey commented on 2017-01-06 12:48:07
"Intro to Rx" says that using subjects is discouraged, because they are only for playing, they "introduce mutability", may have bad performance in future releases, etc.
The question is: how do I then implement a Rx equivalent of C# events? Implementing a c# event then using FromEventPattern seems cumbersome, subjects are "discouraged" what do I use then?
Muhammad Rehan Saeed commented on 2017-01-07 11:10:34
"Intro to Rx" says that using subjects is discouraged, because they are only for playing, they "introduce mutability", may have bad performance in future releases, etc.
The question is: how do I then implement a Rx equivalent of C# events? Implementing a c# event then using FromEventPattern seems cumbersome, subjects are "discouraged" what do I use then?
I've read that too, one of the problems is that you can both publish and subscribe to it which can be dangerous. You hit the nail on the head, how else would you implement events without it? I take the more pragmatic approach. I know the potential pitfalls of using it, I know not to expose the subject outside of the class using it, so I use it.
Andrey commented on 2017-01-08 13:25:01
I've read that too, one of the problems is that you can both publish and subscribe to it which can be dangerous. You hit the nail on the head, how else would you implement events without it? I take the more pragmatic approach. I know the potential pitfalls of using it, I know not to expose the subject outside of the class using it, so I use it.
I see, these rumours about subjects are mostly about functional programming ideas. For those who just want a substitute for dumb C# events, Subject is just right.
Found a good explanation on when to use Subject:
http://davesexton.com/blog/post/To-Use-Subject-Or-Not-To-Use-Subject.aspx
Jesse Liberty commented on 2017-01-16 14:08:33
You may want to take a quick look at http://jliberty.me/2j0ePAP -- thanks
HMIndia commented on 2018-10-18 09:01:35
In High refresh applications (say Stock market) can we claim that use of RX will improve the performance and memory management
Muhammad Rehan Saeed commented on 2018-10-23 09:48:04
In High refresh applications (say Stock market) can we claim that use of RX will improve the performance and memory management
I don't think you can claim that without building it and measuring the difference.
DanClark commented on 2019-10-08 21:31:58
Hi,
I followed your example, are you able to answer this question by any chance? https://stackoverflow.com/questions/58263480/reactive-extension-simple-example-not-working-with-number-generator
Thanks,
Muhammad Rehan Saeed commented on 2019-10-10 20:17:12
Hi,
I followed your example, are you able to answer this question by any chance? https://stackoverflow.com/questions/58263480/reactive-extension-simple-example-not-working-with-number-generator
Thanks,
That's great! StackOverflow is a great place to ask questions. Have an upvote.
I had a quick look. You say it doesn't work but don't describe what the problem is, what do you expect and what actually happens.