Bacon.js Maximum Call Stack Exceeded

穿精又带淫゛_ 提交于 2019-12-22 08:59:42

问题


I'm trying to produce a stream similar to Bacon.fromPoll for requestAnimationFrame

Why does the following code produce a "Maximum call stack exceeded" error?

function rafSequence() {
    var raf = Bacon.fromCallback(function(callback) {
        requestAnimationFrame(function() {
            callback(Date.now());
        });
    });
    return raf.merge(raf.flatMap(rafSequence));
}

rafSequence().log();

I thought merge() would garbage collect when one of the 2 streams threw a Bacon.End (the raf in raf.merge(...). So why does it error?

UPDATE: I have been able to implement a working version as follows:

Bacon.repeat(() => Bacon.fromCallback(requestAnimationFrame));

I am still interested why merge() isn't cleaning up.


回答1:


In the current Bacon.js implementation (0.6.x) all "infinite" sequences based on recursion are bound to fail, because at each step, the "stream stack" gets deeper. I'm sure there is a way to optimize the implementation to cope better with this kind of constructs, but it's far from trivial.

For your particular case, a fromGenerator method would make your implementation simpler. There's already related code in this commit, if you're interested. I suggest you use Github Issues in case you're interested in getting this fixed.



来源:https://stackoverflow.com/questions/20304334/bacon-js-maximum-call-stack-exceeded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!