Skip to content

Commit a5f2397

Browse files
committed
Use async action
1 parent 0b9fafe commit a5f2397

4 files changed

Lines changed: 16 additions & 17 deletions

File tree

backend/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ const program = createProgram({
1818
},
1919
});
2020

21-
program.parse();
21+
program.parseAsync();

backend/dev-cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ const program = createProgram({
2424
},
2525
});
2626

27-
program.parse();
27+
program.parseAsync();

backend/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export function createProgram(inject: Inject): Command {
4343
.description(
4444
"Run webxdc-dev simulator with webxdc from dev server URL, .xdc file or dist directory",
4545
)
46-
.action((location, options) => {
47-
run(
46+
.action(async (location, options) => {
47+
await run(
4848
location,
4949
{ basePort: options.port, csp: options.csp, verbose: options.verbose },
5050
inject,

backend/run.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type Inject = {
1212
getIndexHtml: () => string;
1313
};
1414

15-
function actualRun(appInfo: AppInfo, options: Options, inject: Inject): void {
15+
async function actualRun(appInfo: AppInfo, options: Options, inject: Inject): Promise<void> {
1616
const { injectFrontend, injectSim, getIndexHtml } = inject;
1717
const instances = new Instances(appInfo, injectSim, options);
1818

@@ -37,7 +37,7 @@ function actualRun(appInfo: AppInfo, options: Options, inject: Inject): void {
3737
open("http://localhost:" + options.basePort);
3838
}
3939

40-
export function run(locationStr: string, options: Options, inject: Inject) {
40+
export async function run(locationStr: string, options: Options, inject: Inject): Promise<void> {
4141
let location: Location;
4242
try {
4343
location = getLocation(locationStr);
@@ -57,15 +57,14 @@ export function run(locationStr: string, options: Options, inject: Inject) {
5757

5858
console.log("Starting webxdc project in:", locationStr);
5959

60-
getAppInfo(location)
61-
.then((appInfo) => {
62-
actualRun(appInfo, options, inject);
63-
})
64-
.catch((e) => {
65-
if (e instanceof AppInfoError) {
66-
console.error(e.message);
67-
return;
68-
}
69-
throw e;
70-
});
60+
try {
61+
const appInfo = await getAppInfo(location)
62+
await actualRun(appInfo, options, inject);
63+
} catch (e) {
64+
if (e instanceof AppInfoError) {
65+
console.error(e.message);
66+
return;
67+
}
68+
throw e;
69+
}
7170
}

0 commit comments

Comments
 (0)