Skip to content

Commit

Permalink
fix: always stop previewers when disposing of workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
fwouts committed Aug 30, 2023
1 parent d3940ae commit dc10b13
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export async function createWorkspace({
`Preview.js framework plugin ${frameworkPlugin.name} is too recent. Please upgrade Preview.js or use an older version of ${frameworkPlugin.name}.`
);
}
const activePreviewers = new Set<Previewer>();
const workspace: Workspace = {
frameworkPluginName: frameworkPlugin.name,
crawlFiles: frameworkPlugin.crawlFiles,
Expand Down Expand Up @@ -193,14 +194,20 @@ export async function createWorkspace({
},
});
await previewer.start();
activePreviewers.add(previewer);
return {
url: () => `http://localhost:${port}`,
stop: async () => {
activePreviewers.delete(previewer);
await previewer.stop();
},
};
},
dispose: async () => {
await Promise.all(
[...activePreviewers].map((previewer) => previewer.stop())
);
activePreviewers.clear();
// Note: We may also want to reuse FrameworkPlugin for multiple workspaces, in which case
// dispose() should not be called here?
frameworkPlugin.dispose();
Expand Down

0 comments on commit dc10b13

Please sign in to comment.