Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call stack exceeded for large data generation #9

Open
iongion opened this issue Sep 17, 2013 · 0 comments
Open

Call stack exceeded for large data generation #9

iongion opened this issue Sep 17, 2013 · 0 comments

Comments

@iongion
Copy link

iongion commented Sep 17, 2013

I am using factory-girl together with Faker.js to generate sane large amounts of data, data is generated in an async manner, so i get the "call stack exceeded" message from factory-gril, the code bellow avoids that:

Avoid exceeding call stack:

    asyncForEach(hash.keys(attrs), function(key, cb) {
      var fn = attrs[key];
      if(typeof fn === 'function') {
        fn(function(value) {
          attrs[key] = value;
          setImmediate(function() { cb() })
        });
      } else {
        setImmediate(function() { cb() })
      }
    }, function() {
      var doc = new model();
      var key;
      for(key in attrs) {
        if(attrs.hasOwnProperty(key)) {
          doc[key] = attrs[key];
        }
      }
      setImmediate(function() { callback(doc) })
    });

You might improve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant