Attach connection handler earlier

Summary:
This change attaches our event handlers as soon as the ws is created.

As a consequence, we need to wait until the server has created any necessary instances required to process incoming requests.

To achieve this, I created a type called `Lazy`.

This type wraps around a value and a promise to that value. Callers can check if the value is set. If not, callers can wait for it.

Ultimately, the value can be set outside of the promise itself.

Reviewed By: passy

Differential Revision: D37284939

fbshipit-source-id: 17dec548d7155a3d65440c9584cec07cbb826c37
This commit is contained in:
Lorenzo Blasa
2022-06-21 12:48:43 -07:00
committed by Facebook GitHub Bot
parent 40e65901bd
commit 8c67b049ab
4 changed files with 53 additions and 33 deletions

View File

@@ -16,11 +16,7 @@ import fs from 'fs-extra';
import yargs from 'yargs';
import open from 'open';
import {initCompanionEnv} from 'flipper-server-companion';
import {
attachSocketServer,
startFlipperServer,
startServer,
} from 'flipper-server-core';
import {startFlipperServer, startServer} from 'flipper-server-core';
import {isTest} from 'flipper-common';
const argv = yargs
@@ -97,7 +93,7 @@ async function start() {
console.error('Failed to load keytar:', e);
}
const {app, server, socket} = await startServer({
const {app, server, socket, readyForIncomingConnections} = await startServer({
port: argv.port,
staticDir,
entry: 'index.web.dev.html',
@@ -123,7 +119,7 @@ async function start() {
if (argv.bundler) {
await attachDevServer(app, server, socket, rootDir);
}
attachSocketServer(flipperServer, socket, companionEnv);
await readyForIncomingConnections(flipperServer, companionEnv);
}
start()