[]
        
(Showing Draft Content)

支持异步命令

命令执行过程中可能要发送网络请求等异步操作,而后续命令希望在异步操作完成后执行。

1.通过 async await 方法实现。

class MyPluginCommand extends Forguncy.Plugin.CommandBase{
    async execute() {
        const response = await fetch("http://urlYouWhatToAccess/");
        const resultText = await response.text();
        console.log(resultText);
    }
}

Forguncy.Plugin.CommandFactory.registerCommand("MyPlugin.MyPluginCommand, MyPlugin", MyPluginCommand);

2.通过构建Promise对象实现。

class MyPluginCommand extends Forguncy.Plugin.CommandBase{
    execute() {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                this.log("异步方法被执行,之后会执行后续逻辑");
                resolve();
            }, 3000);
        });
    }
}

Forguncy.Plugin.CommandFactory.registerCommand("MyPlugin.MyPluginCommand, MyPlugin", MyPluginCommand);