RxCpp
RxCpp copied to clipboard
Resource usage
I have problems understanding how to use a resource to create a new observable from scratch. The most trivial example I can come out with is:
rxcpp::observable<>::scope(
[]() { return rxcpp::resource<int>(1); },
[](rxcpp::resource<int> res) {
return rxcpp::observable<>::create<int>(
[res](rxcpp::subscriber<int> sub) {
sub.on_next(res.get());
sub.on_completed();
}
);
}
);
In this case, I would get compilation error as resource::get is not const and my lambda is not mutable. Changing the lambda to mutable leads to #473 . Am I misusing observable::scope? I could not find many information about its correct usage...
Still, to make my code work, I could make mutable the callback in observer as proposed in #473, but I'm wondering if it does makes sense in this case. Is there a compelling reason not to make resource::get() const? By looking at the source I can see that it is just calling get on a shared_ptr (which is const already...).
yes, resource::get
should be const. at some point I would like to revisit the design of scope as well