我正在创建可以正常工作的yeoman生成器,现在我需要添加一个列表从异步(我希望它在后台运行)调用,该过程大约需要2-3秒才能检索到数据,因此我将其放在initializing
内,因为用户将得到第三个问题。 (请参见下面的对象)因此,当用户遇到问题3时,数据检索过程将开始避免等待。基本上,我希望数据检索将在后台过程中完成。.]]
我的问题是:
initialize
方法中运行异步我尝试的是以下内容:
export default class AppGenerator extends Generator {
private listData: ListInstance[];
async initializing() {
this.props = {
appName: "app",
apiName: "app-api",
};
//--------------Here I call to async function --------------//
this.listData = await GetInstances();
}
async prompting() {
const answers = await this.prompt([
{
name: "appName",
message: "Project name: ",
type: "input",
default: this.props.appName,
},
{
name: "apiName",
message: "API name: ",
type: "input",
default: this.props.apiName,
},
{
name: "instanceName",
type: "list",
message: "Choose instance",
choices: this.listData,
},
];
}
writing() {
//here I dont get the `this.answers` , I need to get the values from the answers
}
我正在创建一个可以正常工作的yeoman生成器,现在我需要从异步(我希望它在后台运行)调用中添加一个列表,该列表可能需要2-3秒来检索数据,因此我将其放入...
[一些初步观察: