Skip to content

Commit

Permalink
Let active compilations settle before disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed Nov 14, 2023
1 parent 7906f99 commit ebfddd9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/src/async-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class AsyncCompiler {
/** Whether the underlying compiler has already exited. */
private disposed = false;

/** A record of all compilations */
private compilations: Promise<CompileResult>[] = [];

/** The child process's exit event. */
private readonly exit$ = new Promise<number | null>(resolve => {
this.process.on('exit', code => resolve(code));
Expand Down Expand Up @@ -108,11 +111,13 @@ export class AsyncCompiler {
): Promise<CompileResult> {
this.throwIfDisposed();
const importers = new ImporterRegistry(options);
return this.compileRequestAsync(
const compilation = this.compileRequestAsync(
newCompilePathRequest(path, importers, options),
importers,
options
);
this.compilations.push(compilation);
return compilation;
}

compileStringAsync(
Expand All @@ -121,16 +126,19 @@ export class AsyncCompiler {
): Promise<CompileResult> {
this.throwIfDisposed();
const importers = new ImporterRegistry(options);
return this.compileRequestAsync(
const compilation = this.compileRequestAsync(
newCompileStringRequest(source, importers, options),
importers,
options
);
this.compilations.push(compilation);
return compilation;
}

/** Kills the child process, cleaning up all associated Observables. */
async dispose() {
this.disposed = true;
await Promise.all(this.compilations);
this.process.stdin.end();
await this.exit$;
}
Expand Down

0 comments on commit ebfddd9

Please sign in to comment.