Skip to content

Instantly share code, notes, and snippets.

@zensh
Last active August 29, 2015 14:02
Embed
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!')
});
@zensh
Copy link
Author

zensh commented Jun 1, 2014

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

@hax
Copy link

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