Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] rxcpp protects on_next. Is this intentional? #174

Closed
cult54321 opened this issue Sep 8, 2015 · 2 comments
Closed

[Question] rxcpp protects on_next. Is this intentional? #174

cult54321 opened this issue Sep 8, 2015 · 2 comments

Comments

@cult54321
Copy link

Q1 : rxcpp protects on_next. Is this intentional?

...
  auto handler_next      = [ ] (evt_t i) {throw "aaa";};
  auto handler_error     = [ ] (auto  e) { console::error("on_error: "s + e); };
...
  auto observable   = rx::observable<>::create(on_subscribe);
  auto subscription = observable.subscribe(handler_next,
                                           handler_error,
                                           handler_completed);
...
output>
[11:47:53] [LOG]   ----- test start -----
[11:47:53] [ERROR] on_error: aaa
[11:47:53] [LOG]   on_dispose
[11:47:53] [LOG]   ----- test end    -----

But according to

https://github.com/Reactive-Extensions/RxJS/tree/master/doc/designguidelines#53-protect-calls-to-user-code-from-within-an-operator

Note: do not protect calls to subscribe, dispose, onNext, onError and onCompleted methods. 
These calls are on the edge of the monad. 
Calling the onError method from these places will lead to unexpected behavior.

Q2 : Does Rx Specification exist ? where?

@cult54321 cult54321 changed the title [Question] rxcpp protects on_next. is this intentional? [Question] rxcpp protects on_next. Is this intentional? Sep 8, 2015
@kirkshoop
Copy link
Member

Yes, this is intentional.

The guideline referenced is intended for operator implementation. The protection for on_next is in the subscriber which enforces the observer contract (zero or more on_next followed by either one on_error or one on_completed and then the final unsubscribe).

My primary source for the specification was the Rx.Net source. There have been some changes inspired by RxJava and some others to embrace pay-for-play in C++

There are a variety of articles that explain the contracts for Observable, Observer, Disposable and Scheduler. I have read many - it is somewhat like monad tutorials, there is always a new one begin written..

I would suggest looking at rxmarbles and the learnrx tutorial as good starting places.

@cult54321
Copy link
Author

thanks again your answer and suggestion for learning rx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants