splunk / splunk-sdk-csharp-pcl

Splunk's next generation C# SDK
https://dev.splunk.com/enterprise/docs/csharp
Apache License 2.0
64 stars 46 forks source link

Embrace Rx Zen Nature #6

Closed anaisbetts closed 10 years ago

anaisbetts commented 10 years ago

This PR cleans up a lot of the interface that Rx users would use, to something more idiomatic Rx'y. Note that I haven't actually tested any of this code and it may be completely broken, but it's On The Right Track™ :)

itay commented 10 years ago

@paulcbetts you should change your user name to "Paul Betts™" :)

dahlbyk commented 10 years ago

In the previous commit, once you called AsObservable(), we kept trucking on forever even if the last subscriber dropped off early, until the stream was exhausted.

Instead, have at most one underlying person doing the reads and the rest recieving that result, and if everybody unsubscribes early, we don't Dispose and we stop reading the stream altogether.

So for SearchResults.AsObservable(), ReadResultAsync will be called as soon as someone subscribes, and continue to be called until either:

  1. Everyone has unsubscribed, in which case the observable becomes idle until a new subscriber comes along; or
  2. The stream completes via read returning null (or an error), in which case the SearchResults will be Disposed and all subscribers will receive a completed event (and maybe an error).
anaisbetts commented 10 years ago

@dahlbyk Nailed it

glennblock commented 10 years ago

Hi @paulcbetts thanks for sending this. @David-Noble-at-work and I are reviewing the suggested changes.

glennblock commented 10 years ago

Hi @paulcbetts

Thanks for this PR and for the effort! After consulting with @headinthebox, we've decided not to make this change. The reasoning is that we don't want to require customers to pull in Rx packages in order to use our SDK. With this current model you can use Rx if you need it.

@headinthebox can you weigh in?

Thanks! Glenn

headinthebox commented 10 years ago

It is perfectly valid for producers of IObservable to provide their own implementation with pulling in the whole of Rx, as long as they respect the Rx contract.

The real solution would be to have the source code for a conformant standard implementation of IObservable available for people to re-use (instead of binary reuse of the library). This is the second time I ran into this issue.

Once you have an observable in hand, you can pull in Rx yourself.

[As to wether to be or be convertable to is independent of Observable or Enumerable, i.e. if you are one you should also be the other and vice versa].

glennblock commented 10 years ago

@headinthebox thanks! I agree having this code readily available makes sense. Sounds like a perfect job for a Nuget source package!

anaisbetts commented 10 years ago

Sounds like a perfect job for a Nuget source package!

I don't see how you can do that as a source package, I had to use the class internals to do it. If you're not going to take this change, please remove the existing Rx code and leave IObservable out completely, it's pretty broken and incorrect

glennblock commented 10 years ago

@paulcbetts we had @headinthebox just review the code and he found no issues. What specifically are you seeing as a problem?

The source package would be a way to distribute a default implementation of IObservable.

anaisbetts commented 10 years ago

The ones that stand out are:

Maybe I didn't read the existing code carefully enough though, I may be missing something. I understand the desire to not bolt on all of Rx, but why not just pull in the code for those operators, or use ILMerge?

headinthebox commented 10 years ago

What you point out @paulcbetts are bugs that should be fixed; but the main thing is that we should make it easy for folks to expose IObservable without needing to pull in the whole shebang.