I'm porting some code from C# that heavily relies on Rx, and I have difficulties finding C++ equivalents to some of the most used C# methods.
In particular, I want to create an observable from the subscription/unsubscription logic. In C#, I use the Observable.Create<TSource> Method (Func<IObserver<TSource>, Action>)
override to create an observable. For instance
var observable = Observable.Create<int>(observer =>
{
observers.Add(observer);
return () =>
{
observers.Remove(observer)
};
});
Is it possible to do the same with RxCpp? I think the answer lies in the rx::observable<>::create(OnSubscribe os)
method, but I can't figure out how to use it to "register" an unsubscription lambda.