ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

action_tailrecurser condition explanation #584

Open ignus2 opened 2 years ago

ignus2 commented 2 years ago

Hi, We're using rxcpp to send messages between components in our app, and we are running into some issues with the recursion, and nailed down our problems to action_tailrecurser, where we couldn't figure out the logic behind it. Specifically action_tailrecurser::operator()

    inline void operator()(const schedulable& s, const recurse& r) {
        if (!f) {
            std::terminate();
        }
        trace_activity().action_enter(s);
        auto scope = s.set_recursed(r);
        while (s.is_subscribed()) {
            r.reset();
            f(s);
            if (!r.is_allowed() || !r.is_requested()) {
                if (r.is_requested()) {
                    s.schedule();
                }
                break;
            }
            trace_activity().action_recurse(s);
        }
        trace_activity().action_return(s);
    }

We can't really understand this condition:

            if (!r.is_allowed() || !r.is_requested()) {
                if (r.is_requested()) {
                    s.schedule();
                }
                break;
            }

What is this trying to do? Can someone explain it in plain english please? :) Thank you in advance!