How to catch cyclic dependency between observables?


  • I have a user-programming scenario where user can end up creating two observables that depend on each other. RxJS does not allow cyclic dependencies, as far as I can see, the memory or stack reaches its limits and the onError callback is triggered with the value TRUE. However, I would like to detect the cyclic dependency explicitly and throw an more descriptive error message.
    Any suggestions as to how to do that?

    This codes illustrates how to create a cyclic dependency in RxJS:

    var obs = {};
    obs.a = Rx.Observable.returnValue(42).combineLatest(obs.b, function (a, b) {
        return a + b;
    obs.b = Rx.Observable.returnValue(42).combineLatest(obs.a, function (b, a) {
        return b + a;
    obs.a.subscribe(function(val) {
    function(err) {
    function() {
    The error message is simply "true".

    • Edited by Egil Hansen Saturday, June 29, 2013 9:28 PM
    Saturday, June 29, 2013 9:26 PM