-
Notifications
You must be signed in to change notification settings - Fork 22
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
creating an observable from C callback functions #496
Comments
Hi! Yeah, pretty interesting task. Due to c-style function pointer is stateless (i mean, we can't pass lambda with some capture) and it doesn't provide extra https://rpp.godbolt.org/z/5azdnh67h There are 2 options, not sure which one is more appropriate for your needs. First one looks much more straightforward, second one is more "reactive" (call to If it is not suitable solution, feel free to provide some additional details/requirements =) |
Thank-you so much for taking a look. I can give you a Here is what I have: https://rpp.godbolt.org/z/9MxsYhGhK Crux:
It is so "awesome" that it causes clang to crash. GCC will eat it. The crash is bad enough, but from a pattern standpoint, creating a new subject just so I can delete it feels like I am doing it wong. |
In this case you can do it even much easier In short: we are doing raw detached copy of original observer instead of providing extra indirection via subject But there is difference in behavior:
So, i mean this one: const auto connectable = observable | rpp::ops::publish();
connectable.connect(); // there actually happens subscription of "nothing" to your observable and it starts do_async_thing
// then subscribe as regular
connectable.subscribe(....); or const auto resulting_observable = observable | rpp::ops::publish() | rpp::ops::ref_count();
resulting_observable.subscribe(....); // this one initiates do_async_thing
resulting_observable.subscribe(....); // this one just connects to previous do_async_thing BTW: looks like clang is crashing due to using latches in unexpected way |
Thank you! I can work with this.
Interesting, I did not expect that was the problem. Is capturing not allowed (or not well formed)? Using your setup:
This takes down |
Yeah, looks interesting.. have to check it later |
Made attemp to fix. |
Fixed on godbolt (compilation results of exactly same source are cached, so, have to modify it in anyway - atleast add space at any place) |
I cannot figure out the correct way to create an observable from a C style emitter with callback functions. Example shape:
I have a solution of sorts, but it is almost certainly "wrong" as it involves creating a dynamic object and cleaning up. Rather than lead with my incorrect approach, better to just ask flatly how to turn the above into an observable to which I can subscribe. The key point in the setup above is that all the "state" is maintained inside the black box which is
do_async_thing()
. It takes care of whatever state it needs to emit C strings, I don't. I am sure the solution is "obvious" once I see it, but I've tried at length and appear to be missing something fundamental. TIA.The text was updated successfully, but these errors were encountered: