Skip to content

Commit

Permalink
Merge of #6144
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 4, 2024
2 parents 4f51239 + da4e007 commit 5c6143c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
11 changes: 9 additions & 2 deletions apps/wing-console/console/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export type RouteNames = keyof inferRouterInputs<Router> | undefined;

export { isTermsAccepted } from "./utils/terms-and-conditions.js";

const enableSimUpdates =
process.env.WING_ENABLE_INPLACE_UPDATES === "true" ||
process.env.WING_ENABLE_INPLACE_UPDATES === "1";

export interface CreateConsoleServerOptions {
wingfile: string;
log: LogInterface;
Expand Down Expand Up @@ -134,7 +138,10 @@ export const createConsoleServer = async ({
let isStarting = false;
let isStopping = false;

const simulator = createSimulator({ stateDir });
const simulator = createSimulator({
stateDir,
enableSimUpdates,
});
if (onTrace) {
simulator.on("trace", onTrace);
}
Expand All @@ -150,7 +157,7 @@ export const createConsoleServer = async ({
platform,
testing: true,
});
const testSimulator = createSimulator();
const testSimulator = createSimulator({ enableSimUpdates });
testCompiler.on("compiled", ({ simfile }) => {
testSimulator.start(simfile);
});
Expand Down
24 changes: 18 additions & 6 deletions apps/wing-console/console/server/src/utils/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Simulator {

export interface CreateSimulatorProps {
stateDir?: string;
enableSimUpdates?: boolean;
}

const stopSilently = async (simulator: simulator.Simulator) => {
Expand All @@ -45,13 +46,25 @@ const stopSilently = async (simulator: simulator.Simulator) => {
export const createSimulator = (props?: CreateSimulatorProps): Simulator => {
const events = new Emittery<SimulatorEvents>();
let instance: simulator.Simulator | undefined;
const handleExistingInstance = async (simfile: string): Promise<boolean> => {
if (!instance) {
return true;
}
if (props?.enableSimUpdates) {
await events.emit("starting", { instance });
await instance.update(simfile);
await events.emit("started");
return false;
} else {
await events.emit("stopping");
await stopSilently(instance);
return true;
}
};
const start = async (simfile: string) => {
try {
if (instance) {
await events.emit("starting", { instance });
await instance.update(simfile);
await events.emit("started");
} else {
const shouldStartSim = await handleExistingInstance(simfile);
if (shouldStartSim) {
instance = new simulator.Simulator({
simfile,
stateDir: props?.stateDir,
Expand All @@ -61,7 +74,6 @@ export const createSimulator = (props?: CreateSimulatorProps): Simulator => {
events.emit("trace", trace);
},
});

await events.emit("starting", { instance });
await instance.start();
await events.emit("started");
Expand Down

0 comments on commit 5c6143c

Please sign in to comment.