Create a gist now

Instantly share code, notes, and snippets.

@zensh /demo.js
Last active Aug 29, 2015

What would you like to do?
'Maximum call stack size exceeded' in 'co'
'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!')
});
Owner

zensh commented Jun 1, 2014

由于 co 的 error 是异步抛出,所以看不到Maximum call stack size exceeded,若想看必须在 co 内部console

hax commented Jun 1, 2014

改成这样就好了:

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