rehansaeed.github.io icon indicating copy to clipboard operation
rehansaeed.github.io copied to clipboard

[Comment] Reactive Extensions (Rx) - Part 1 - Replacing C# Events

Open RehanSaeed opened this issue 5 years ago • 15 comments

https://rehansaeed.com/reactive-extensions-part1-replacing-events/

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Tony Tony commented on 2014-10-24 00:36:27

Thanks for that. Very helpful in seeing the bigger picture.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

jacob jacob commented on 2014-12-23 17:06:30

Great blog! thanks for the help, makes alot more sense now

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Abhinav Singh 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

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed 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 of this.planeSpotted.OnNext(foo);? My understanding is correct? Please reply

Yes that's correct. I've now corrected it.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Reader Man Reader Man commented on 2016-06-04 14:53:49

Thanks a lot on this series.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Sam Sam commented on 2016-08-17 15:45:07

When is this called?

public void AllPlanesSpotted()
{
    this.planeSpotted.OnCompleted();
}

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Andrey 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?

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Andrey 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

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Jesse Liberty Jesse Liberty commented on 2017-01-16 14:08:33

You may want to take a quick look at http://jliberty.me/2j0ePAP -- thanks

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

HMIndia 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

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

DanClark 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,

RehanSaeed avatar May 12 '20 11:05 RehanSaeed

Muhammad Rehan Saeed 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.

RehanSaeed avatar May 12 '20 11:05 RehanSaeed