Skip to content

Error: generatorFunction must be a function

glmdgrielson edited this page Oct 15, 2017 · 3 revisions

Error: generatorFunction must be a function

You are getting this error when trying to use either Promise.coroutine or Promise.spawn and not passing it a generator function as a parameter. For example:

Promise.spawn(function* () { // Note the * 
    var data = yield $.get("http://www.example.com");
    var moreUrls = data.split("\n");
    var contents = [];
    for( var i = 0, len = moreUrls.length; i < len; ++i ) {
        contents.push(yield $.get(moreUrls[i]));
    }
    return contents;
});

Please refer to the relevant section in the documentation about Generators in order to get usage instructions:

Note: Bluebird used to eagerly check for generators which caused problems with transpilers. Because of this, you might get an error similar to TypeError: Cannot read property 'next' of undefined if you pass a function instead of a generator function to Bluebird.

Promise.spawn and Promise.coroutine are built to work with generators to form C# like async/await