Update ready promise (#1320)

This commit is contained in:
Nathan Bierema 2023-01-08 14:12:15 -05:00 committed by GitHub
parent c9293470ec
commit 69833d35b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 18 deletions

View File

@ -56,7 +56,7 @@ export function inject(
startFlag,
' require("' + name + '")(' + JSON.stringify(options) + ')',
' .then(_remotedev =>',
' _remotedev.on("ready", () => {',
' _remotedev.ready.then(() => {',
' if (!_remotedev.portAlreadyUsed) console.log("-".repeat(80));',
' ' + serverFlag,
' })',

View File

@ -87,10 +87,8 @@ if (argv.injectserver) {
);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
server(argv).then(async function (r) {
if (argv.open && argv.open !== 'false') {
await r.listener('ready').once();
await openApp(argv.open as string, options);
}
});
const response = await server(argv);
if (argv.open && argv.open !== 'false') {
await response.ready;
await openApp(argv.open as string, options);
}

View File

@ -13,7 +13,7 @@ const LOG_LEVEL_INFO = 3;
export default async function (argv: { [arg: string]: any }): Promise<{
portAlreadyUsed?: boolean;
listener: (eventName: 'ready') => { once(): Promise<void> };
ready: Promise<void>;
}> {
const options = Object.assign(getOptions(argv), {
allowClientPublish: false,
@ -29,13 +29,7 @@ export default async function (argv: { [arg: string]: any }): Promise<{
}
return {
portAlreadyUsed: true,
listener: function () {
return {
once() {
return Promise.resolve();
},
};
},
ready: Promise.resolve(),
};
}
@ -135,6 +129,9 @@ export default async function (argv: { [arg: string]: any }): Promise<{
})();
httpServer.listen(options.port);
// @ts-expect-error Shouldn't there be a 'ready' event?
return agServer;
return {
ready: (async () => {
await agServer.listener('ready' as 'error').once();
})(),
};
}