forked from petkaantonov/bluebird
-
Notifications
You must be signed in to change notification settings - Fork 0
Error: generatorFunction must be a function
benjamingr edited this page Feb 7, 2014
·
2 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.coroutineare built to work with generators to form C# likeasync/await`