Skip to content

Commit

Permalink
Add support to async queueGenerator.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 5, 2021
1 parent 2e65ccb commit e4a8143
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Environment extends Base {
rootCommand.emit('yeoman:environment', command.env);

const generator = command.env.instantiate(GeneratorClass, this.args, this.opts());
command.env.queueGenerator(generator);
await command.env.queueGenerator(generator);
return command.env.start().then(() => command.env);
});
return command;
Expand Down Expand Up @@ -922,29 +922,26 @@ class Environment extends Base {
// Generator > 5
this.once('run', () => generator.emit('run'));
this.once('end', () => generator.emit('end'));
generator.queueTasks();
} else {
if (!generator.options.forwardErrorToEnvironment) {
generator.on('error', error => this.emit('error', error));
}
generator.promise = generator.run();
return generator.queueTasks();
}
if (!generator.options.forwardErrorToEnvironment) {
generator.on('error', error => this.emit('error', error));
}
generator.promise = generator.run();
};

if (schedule) {
this.runLoop.add(
'environment:run',
(done, stop) => {
try {
runGenerator();
done();
} catch (error) {
stop(error);
}
async () => {
await runGenerator();
}
);
} else {
runGenerator();
const maybePromise = runGenerator();
if (maybePromise && maybePromise.then) {
return maybePromise.then(() => generator);
}
}
return generator;
}
Expand Down Expand Up @@ -1065,7 +1062,7 @@ class Environment extends Base {
async runGenerator(generator) {
try {
generator = await generator;
generator = this.queueGenerator(generator);
generator = await this.queueGenerator(generator);
} catch (error) {
return Promise.reject(error);
}
Expand Down

0 comments on commit e4a8143

Please sign in to comment.