'Maximum call stack size exceeded' in 'co'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*global console*/ | |
// co version 3.0.6 | |
var co = require('co'); | |
function task(callback) { | |
callback(null, 1); | |
}; | |
// 10000 will throw a 'Maximum call stack size exceeded' error | |
co(function *(){ | |
for (var i = 0, l = 10000; i < l; i++) { | |
yield task; | |
} | |
})(function(){ | |
console.log('Success!') | |
}); |
改成这样就好了:
function task(callback) {
setImmediate(function () { callback(null, 1) });
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
由于 co 的 error 是异步抛出,所以看不到
Maximum call stack size exceeded
,若想看必须在 co 内部console